using BenchmarkDotNet.Running;
using BenchmarkDotNet.Attributes;
using System.Collections.Generic;
using System.Collections;
public static void Main()
BenchmarkRunner.Run<Benchmarks>();
[Params(1, 10, 100, 1000, 10000, 100000)]
public void IterationSetup()
int[] values = Enumerable.Range(0, N).ToArray();
a = new A.SomeDataStructure<int>() { values = values.ToArray() };
b = new B.SomeDataStructure<int>() { values = values.ToArray() };
c = new C.SomeDataStructure<int>() { values = values.ToArray() };
b.Stepper(x => { sum += x; });
c.Stepper<int, SumStatic>(sum);
struct SumStatic : IAction<int>
Ref<int> sumValue = new();
SumNonStatic sum = new(sumValue);
c.Stepper<int, SumNonStatic>(sum);
struct SumNonStatic : IAction<int>
public SumNonStatic(Ref<int> value) => sum = value;
c.Stepper(x => { sum += x; });
Console.WriteLine($"BLAH BLAH N{N} sum{sum}");
interface IDataStructure<T> : IEnumerable<T> { }
class SomeDataStructure<T> : IDataStructure<T>
public IEnumerator<T> GetEnumerator()
foreach (T value in values)
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
interface IDataStructure<T>
bool Stepper(Func<T, bool> func);
class SomeDataStructure<T> : IDataStructure<T>
public bool Stepper(Func<T, bool> func)
foreach (T value in values)
public static void Stepper<T>(this IDataStructure<T> dataStructure, Action<T> action)
dataStructure.Stepper(x => { action(x); return false; });
public interface IAction<T1>
public interface IFunc<T1, TResult>
interface IDataStructure<T>
bool Stepper<Step>(Step step)
where Step : struct, IFunc<T, bool>;
class SomeDataStructure<T> : IDataStructure<T>
public bool Stepper<Step>(Step step = default)
where Step : struct, IFunc<T, bool>
foreach (T value in values)
public static void Stepper<T, Step>(this IDataStructure<T> dataStructure, Step step)
where Step : struct, IAction<T>
StepBreakFromAction<T, Step> breakableStep = new() { StepFunction = step };
dataStructure.Stepper<StepBreakFromAction<T, Step>>(breakableStep);
public struct StepBreakFromAction<T, Step> : IFunc<T, bool>
where Step : struct, IAction<T>
internal Step StepFunction;
public bool Do(T value) { StepFunction.Do(value); return false; }
public static void Stepper<T>(this IDataStructure<T> dataStructure, Action<T> step)
StepBreakFromAction<T, ActionRuntime<T>> breakableStep = new() { StepFunction = step };
dataStructure.Stepper<StepBreakFromAction<T, ActionRuntime<T>>>(breakableStep);
public struct ActionRuntime<T1> : IAction<T1>
internal Action<T1> _delegate;
public void Do(T1 arg1) => _delegate(arg1);
public static implicit operator ActionRuntime<T1>(Action<T1> @delegate) => new() { _delegate = @delegate, };