|
using System.Diagnostics;
namespace SparkAPI.Common.Diagnostics
{
/// <summary>
/// Provides a mechanism to benchmark the amount of time something takes. The benchmark will automatically
/// start when instanced.
/// </summary>
public class Benchmark
{
/// <summary>Internal stopwatch for tracking benchmark</summary>
private readonly Stopwatch _stopWatch = new Stopwatch();
/// <summary>Benchmark name</summary>
public string Name { get; private set; }
/// <summary>
/// Benchmark constructor
/// </summary>
/// <param name="name">Benchmark name</param>
public Benchmark(string name)
{
Name = name;
_stopWatch.Start();
}
/// <summary>
/// Seconds elapsed since benchmark initiated
/// </summary>
public double Elapsed
{
get { return _stopWatch.Elapsed.TotalSeconds; }
}
/// <summary>
/// Writes elapsed time to Debug
/// </summary>
public void WriteToConsole()
{
Debug.WriteLine(Name + ":\t" + Elapsed);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Paul Francis currently works as a senior engineer at The Trade Desk.
He holds an undergraduate Honours degree in Finance, and is near completion of a Ph.D. in Market Microstructure, specialising in order flow modelling, and market data processing, reconstruction and analytics.
He is also the creator of Sharp Spark (Spark API SDK), an open source component designed to facilitate the processing of real-time market data from the Spark API:
http://sourceforge.net/projects/sparkapi
Paul lives in Sydney, Australia.