OpTimePair vMulPerf(int samples, long cycles) { var lhs1 = RVec <double>(samples); var rhs1 = RVec <double>(samples); var dst1 = BlockVector.Alloc <double>(samples); var sw1 = stopwatch(); for (var i = 0; i < cycles; i++) { mathspan.mul(lhs1, rhs1, dst1.Unblocked); } var time1 = OpTime.Define(cycles, snapshot(sw1), "gmath"); var lhs2 = lhs1.Replicate(); var rhs2 = rhs1.Replicate(); var dst2 = dst1.Replicate(true); var sw2 = stopwatch(); for (var i = 0; i < cycles; i++) { mkl.mul(lhs2, rhs2, ref dst2); } var time2 = OpTime.Define(cycles, snapshot(sw2), "mkl"); return(time1, time2); }
void run_mean_bench() { var cycles = Pow2.T12; var samples = Pow2.T14; var src = Random.Array <long>(samples, closed(-2000L, 2000L)).Convert <double>(); var ds = Dataset.Load(src); var dst = 0.0; var last = 0.0; var sw1 = stopwatch(); for (var i = 0; i < cycles; i++) { last = ds.Mean(ref dst); } var t1 = OpTime.Define(cycles * samples, snapshot(sw1), "mkl-ssmean"); var sw2 = stopwatch(); for (var i = 0; i < cycles; i++) { last = src.Avg(); } var t2 = OpTime.Define(cycles * samples, snapshot(sw2), "direct"); Collect((t1, t2)); }
/// <summary> /// Measures the respective times required to execute a pair of functions, each of which /// iterate a computational block a specified number of times /// </summary> /// <param name="n">The number of computational block iterations</param> /// <param name="left">The first function</param> /// <param name="right">THe second function</param> public static OpTimePair measure(long n, string leftLabel, string rightLabel, Action <long> left, Action <long> right) { var lTimer = stopwatch(); left(n); var lTime = OpTime.Define(n, snapshot(lTimer), leftLabel); var rTimer = stopwatch(); right(n); var rTime = OpTime.Define(n, snapshot(rTimer), rightLabel); OpTimePair result = (lTime, rTime); return(result); }
OpTime avg_bench(bool reference) { OpTime refbench() { var sw = stopwatch(false); for (var i = 0; i < SampleSize; i++) { var x = Random.Span256 <byte>(); var y = Random.Span256 <byte>(); sw.Start(); var b = math.avgi(x, y); sw.Stop(); } return(OpTime.Define <byte>(SampleSize, sw, $"vavg-ref")); } OpTime opbench() { var sw = stopwatch(false); for (var i = 0; i < SampleSize; i++) { var x = Random.CpuVec256 <byte>(); var y = Random.CpuVec256 <byte>(); sw.Start(); var a = dinx.avg(x, y); sw.Stop(); } return(OpTime.Define <byte>(SampleSize, sw, $"vavg")); } if (reference) { return(refbench()); } else { return(opbench()); } }
OpTime slli256u16Bench(int blocks, int cycles) { var blocklen = Vec256 <ushort> .Length; var opcount = blocks * cycles * blocklen; var shiftRange = closed <byte>(2, 14); var sw = stopwatch(false); var src = Random.Stream <ushort>(); var offsets = Random.Stream(shiftRange); for (var cycle = 0; cycle < cycles; cycle++) { for (var block = 0; block < blocks; block++) { var x = Vec256.Load(src.TakeSpan(blocklen)); var offset = offsets.First(); sw.Start(); Bits.sll(x, offset); sw.Stop(); } } return(OpTime.Define(opcount, snapshot(sw), "slli16u")); }
public static OpTime optime(long opcount, Duration time, [CallerMemberName] string label = null) => OpTime.Define(opcount, time, label);
public static OpTime optime(long opcount, Stopwatch sw, [CallerMemberName] string label = null) => OpTime.Define(opcount, snapshot(sw), label);