Last active
February 3, 2019 00:16
-
-
Save duckymirror/1690cb086cef46521676ff06bdfb3b7d to your computer and use it in GitHub Desktop.
This measures the time for conversions of integers to strings and logging them in the console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
namespace WriteLineSpeed | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Stopwatch stopwatch = new Stopwatch(); | |
Console.WriteLine("Conversion tests"); | |
Console.WriteLine("i + \"\""); | |
stopwatch.Start(); | |
for (int i = 0; i < 1000000; i++) | |
{ | |
string s = i + ""; | |
} | |
Console.WriteLine(stopwatch.ElapsedMilliseconds); | |
Console.WriteLine("i.ToString()"); | |
stopwatch.Restart(); | |
for (int i = 0; i < 1000000; i++) | |
{ | |
string s = i.ToString(); | |
} | |
Console.WriteLine(stopwatch.ElapsedMilliseconds); | |
Console.WriteLine("Console.WriteLine tests"); | |
Console.WriteLine("i+\"\""); | |
stopwatch.Restart(); | |
for (int i = 0; i < 1000; i++) | |
{ | |
Console.WriteLine(i + ""); | |
} | |
Console.WriteLine(stopwatch.ElapsedMilliseconds); | |
Console.WriteLine("---------------------------------"); | |
Console.WriteLine("i"); | |
stopwatch.Restart(); | |
for (int i = 0; i < 1000; i++) | |
{ | |
Console.WriteLine(i); | |
} | |
Console.WriteLine(stopwatch.ElapsedMilliseconds); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment