Last active
September 7, 2018 21:34
-
-
Save markfinal/d7f16fef54499fb379bdf022fd31a266 to your computer and use it in GitHub Desktop.
Test case exercising the speed of Console.SetCursorPosition in .NET core 2.1
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; | |
namespace test | |
{ | |
class Program | |
{ | |
static void TimeConsoleOutput(bool withCarriageReturn) | |
{ | |
var sw = System.Diagnostics.Stopwatch.StartNew(); | |
for (int i = 0; i < 100; i++) | |
{ | |
Console.Write("Hello World! {0}%", i); | |
if (withCarriageReturn) | |
{ | |
Console.SetCursorPosition(0, Console.CursorTop); | |
} | |
} | |
sw.Stop(); | |
Console.WriteLine(); | |
if (withCarriageReturn) | |
{ | |
Console.WriteLine("With carriage return in {0} ms", sw.ElapsedMilliseconds); | |
} | |
else | |
{ | |
Console.WriteLine("Without carriage return in {0} ms", sw.ElapsedMilliseconds); | |
} | |
} | |
static void Main(string[] args) | |
{ | |
TimeConsoleOutput(false); | |
TimeConsoleOutput(true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment