tand/test/Tand.Core.Benchmarks/ExecutionTimeTand.cs
Peter Kurfer d8d307545f
Refactored
- Added Benchmarks
- Added Nuke build
- Refactored directory structure
- Generated GitHub Actions config from Nuke
- Added tool to handle benchmarking from Nuke
2020-03-21 01:10:20 +01:00

35 lines
No EOL
868 B
C#

using System;
using System.Diagnostics;
using Tand.Core.Api;
using Tand.Core.Models;
namespace Tand.Core.Benchmarks
{
public class ExecutionTimeTand<T> : ITandTarget<T>
{
private readonly Stopwatch _stopwatch;
private readonly Action<string>? _resultHandler;
public ExecutionTimeTand() : this(null)
{
}
public ExecutionTimeTand(Action<string>? resultHandler)
{
_stopwatch = new Stopwatch();
_resultHandler = resultHandler;
}
public void OnEnterMethod(CallEnterContext<T> enterContext)
{
_stopwatch.Start();
}
public void OnLeaveMethod(CallLeaveContext<T> leaveContext)
{
_stopwatch.Stop();
_resultHandler?.Invoke($"Total execution time: {_stopwatch.Elapsed}");
}
}
}