PowerShell/test/perf/dotnet-tools/BenchmarkDotNet.Extensions/PartitionFilter.cs

27 lines
891 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BenchmarkDotNet.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Running;
public class PartitionFilter : IFilter
{
private readonly int? _partitionsCount;
private readonly int? _partitionIndex; // indexed from 0
private int _counter = 0;
public PartitionFilter(int? partitionCount, int? partitionIndex)
{
_partitionsCount = partitionCount;
_partitionIndex = partitionIndex;
}
public bool Predicate(BenchmarkCase benchmarkCase)
{
if (!_partitionsCount.HasValue || !_partitionIndex.HasValue)
return true; // the filter is not enabled so it does not filter anything out and can be added to RecommendedConfig
return _counter++ % _partitionsCount.Value == _partitionIndex.Value; // will return true only for benchmarks that belong to its partition
}
}