Skip to content

Instantly share code, notes, and snippets.

@jeffijoe
Created September 11, 2014 14:31
Show Gist options
  • Save jeffijoe/f4b36b37589931a807b8 to your computer and use it in GitHub Desktop.
Save jeffijoe/f4b36b37589931a807b8 to your computer and use it in GitHub Desktop.
C# "Benchmark" helper.
// Benchmark.cs
// Author: Jeff Hansen <jeff@memberlink.com>
using System;
using System.Diagnostics;
namespace Sharp2D.Tests.EngineTests.TestHelpers
{
/// <summary>
/// Benchmark helper.
/// </summary>
public static class Benchmark
{
private static Stopwatch _sw = new Stopwatch();
/// <summary>
/// Starts the benchmark, and writes the passed message to the console.
/// </summary>
/// <param name="messageForConsole">The message for console.</param>
public static void Start(string messageForConsole)
{
Console.Write(messageForConsole);
_sw.Restart();
}
/// <summary>
/// Ends the benchmark and prints the elapsed time to the console.
/// </summary>
public static void End()
{
_sw.Stop();
Console.WriteLine(" {0}ms", _sw.ElapsedMilliseconds);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment