30 lines
807 B
C#
30 lines
807 B
C#
using Process.Abstract;
|
|
using Process.Interface;
|
|
using System.Diagnostics;
|
|
|
|
namespace CLI.Processor;
|
|
|
|
public class StopwatchProcessor<TInput, TOutput> : Processor<TInput, TOutput>
|
|
{
|
|
private readonly IProcessor<TInput, TOutput> _processor;
|
|
|
|
/// <summary>
|
|
/// Execution time of the last processing action
|
|
/// </summary>
|
|
public TimeSpan? Elapsed { get; private set; }
|
|
|
|
public StopwatchProcessor(IProcessor<TInput, TOutput> processor) => _processor = processor;
|
|
|
|
public override IEnumerable<TOutput> Process(IEnumerable<TInput> inputs)
|
|
{
|
|
var stopWatch = Stopwatch.StartNew();
|
|
var results = _processor.Process(inputs);
|
|
stopWatch.Stop();
|
|
Elapsed = stopWatch.Elapsed;
|
|
return results;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override string? ToString() => _processor.ToString();
|
|
}
|