import std.conv, std.datetime, std.random, std.range, std.stdio; import std.math: isNaN; struct S { bool b; double d; } void main() { auto arr = new S[1_000_000]; size_t count = 100 * arr.length; foreach (ref a; arr) { a.b = false; a.d = double.nan; } auto sample = randomSample(iota(arr.length), 1 * arr.length / 10); foreach (s; sample) { arr[s].b = true; arr[s].d = double.infinity; } StopWatch watch; size_t i = 0; watch.start(); foreach (a; cycle(arr).take(count)) { if (!a.b) { ++i; } } watch.stop(); real timeBool = to!real(watch.peek.usecs); writeln("Time for ", count, " if(boolean)'s with ", i, " counts of true: ", timeBool, " microseconds [", timeBool / count, " per test]."); watch.reset; i = 0; watch.start(); foreach (a; cycle(arr).take(count)) { if (isNaN(a.d)) { ++i; } } watch.stop(); real timeNaN = to!real(watch.peek.usecs); writeln("Time for ", count, " if(isNaN)'s with ", i, " counts of true: ", timeNaN, " microseconds [", timeNaN / count, " per test]."); writeln; writeln("Total difference: ", timeBool - timeNaN, " [", (timeBool - timeNaN) / count, " per test]."); }