Skip to content

Instantly share code, notes, and snippets.

@markfinal
Last active September 7, 2018 21:34
Show Gist options
  • Save markfinal/d7f16fef54499fb379bdf022fd31a266 to your computer and use it in GitHub Desktop.
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
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