page sample
This commit is contained in:
37
PacticeSolution/StringBuilderTest/Program.cs
Normal file
37
PacticeSolution/StringBuilderTest/Program.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace StringBuilderTest
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int cnt = 100000;
|
||||
Stopwatch sw = new Stopwatch();
|
||||
|
||||
Console.WriteLine("Test1\tString");
|
||||
sw.Start();
|
||||
|
||||
string s = "";
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
s += i;
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
Console.WriteLine($"Elapsed: {sw.ElapsedMilliseconds}ms");
|
||||
|
||||
Console.WriteLine("Test2\tStringBuilder");
|
||||
sw.Restart();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
sb.Append(i);
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
Console.WriteLine($"Elapsed: {sw.ElapsedMilliseconds}ms");
|
||||
}
|
||||
}
|
||||
}
|
10
PacticeSolution/StringBuilderTest/StringBuilderTest.csproj
Normal file
10
PacticeSolution/StringBuilderTest/StringBuilderTest.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user