Undocumented in source. Be warned that the author may not have intended to support it.
1 @trusted auto getStdoutRange() 2 { 3 import std.stdio : stdout; 4 5 return stdout.lockingTextWriter; 6 } 7 //Lump the benchmarks together somewhere. 8 static class StaticStore 9 { 10 11 import chimpfella.kernels; 12 import chimpfella.measurement; 13 import std.range : iota, repeat; 14 import std.random : uniform; 15 16 enum meas = [PhobosTimer("A stub").toMeasurement]; 17 18 @FunctionBenchmark!("Something with an integer", iota(1, 50), (x) => uniform(-x, x))(meas) static void func( 19 int l) 20 { 21 uint x; 22 import core.volatile; 23 24 foreach (_; 0 .. l) 25 volatileStore(&x, _); 26 } 27 28 static auto getRandPair(T)(int x) 29 { 30 import std.random; 31 32 struct rndParams 33 { 34 AliasSeq!(T, T) pack; 35 } 36 37 rndParams tmp; 38 auto rnd = Random(unpredictableSeed); 39 40 // Generate an integer in [0, 1023] 41 tmp.pack[0] = cast(T) uniform(0, 1024, rnd); 42 tmp.pack[1] = cast(T) uniform(0, 1024, rnd); 43 return tmp; 44 } 45 46 @TemplateBenchmark!(0, int, float, double) @FunctionBenchmark!("Templated add benchmark", 47 0.repeat(100), ForwardTemplate!(getRandPair))(meas) static T templatedAdd(T)(T x, 48 T y) 49 { 50 return x + y; 51 } 52 import std.algorithm; 53 import std.array; 54 static string ctfeRepeater(int n) 55 { 56 return "cpuid;".repeat(n).join(); 57 } 58 59 enum cpuidRange = iota(1, 10).map!(ctfeRepeater).array; 60 @TemplateBenchmark!(0, cpuidRange) 61 @FunctionBenchmark!("Measure", iota(1, 10), (_) => [1, 2, 3, 4])(meas) 62 static int sum(string asmLine)(inout int[] input) 63 { 64 //This is quite fun because ldc will sometimes get rid of the entire function body and just loop over the asm's 65 int tmp; 66 foreach (i; input) 67 { 68 mixin("asm { ", asmLine, ";}"); 69 } 70 return tmp; 71 } 72 73 alias summat = sum!"mfence"; 74 } 75 76 @safe struct PrintData 77 { 78 import chimpfella.measurement; 79 80 auto getOutputHandle(string benchmarkName, scope const Measurements[] counters) 81 { 82 struct outputVoldy 83 { 84 string name; 85 size_t width; 86 import std; 87 88 //You don't have to do anything with the header 89 this(string setName, scope const Measurements[] them) 90 { 91 name = setName; 92 writefln!"---------------%s---------------"(setName); 93 auto counterPut = counters.map!(x => x.getHeader); 94 //pragma(msg, ElementType!(typeof(counterPut))); 95 writeln("I;", counterPut.joiner!(typeof(counterPut)).joiner.joiner(";")); 96 } 97 98 void put(scope size_t[] data) 99 { 100 data.map!(s => s.to!string).joiner(";").writeln; 101 } 102 103 } 104 105 return outputVoldy(benchmarkName, counters); 106 } 107 } 108 109 PrintData outBuf; 110 auto dataOutput = MetaExecution!PrintData(outBuf); 111 ExecuteBenchmarks!(StaticStore).run(dataOutput);
Execute benchmarks from fromHere - i.e. this runs ExecutionEngine for you all those Benchmarks