XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.NetCore.XUnit

【DLL】提供方便快捷的测试,无需编写Main方法,可直接添加特性在类或方法上进行测试

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEExtension.NetCore.XUnit.Benchmarking;

namespace XFEExtension.NetCore.XUnit.Test;

internal sealed class ScriptedBenchmarkClock(IReadOnlyList<long> elapsedTicks) : IBenchmarkClock
{
    private int _timestampCall;
    private long _timestamp;

    public long Frequency => 10_000_000;

    public long GetTimestamp()
    {
        if ((_timestampCall++ & 1) == 0)
            return _timestamp;
        var durationIndex = _timestampCall / 2 - 1;
        if (durationIndex >= elapsedTicks.Count)
            throw new InvalidOperationException("The benchmark requested more clock samples than the test supplied.");
        _timestamp += elapsedTicks[durationIndex];
        return _timestamp;
    }

    public double GetElapsedNanoseconds(long startTimestamp, long endTimestamp) =>
        (endTimestamp - startTimestamp) * (1_000_000_000d / Frequency);
}