Untitled

mail@pastecode.io avatar
unknown
csharp
2 years ago
701 B
2
Indexable
Never
public void Test(Action algorithm, int iterationNumber, string name)
{
    long result = 0;
    var localResults = new long[iterationNumber];
    for (int i = 0; i < iterationNumber; i++)
    {
        var startMemory = GC.GetTotalMemory(false);
        algorithm.Invoke();
        var endMemory = GC.GetTotalMemory(false);
        result = result + endMemory - startMemory;
    }
    result = result < 0 ? LastResult.Result : result /= iterationNumber;
    var resultId = AllResults.Count(x => x.AlgorithmName == name) + 1;
    TestResult<long> testResult = new(resultId,name, result, localResults);
    LastResult = testResult;
    lock (AllResults)
    {
        AllResults.Add(testResult);
    }
}