import 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]; foreach (ref a; arr) { a.b = false; a.d = double.nan; } auto sample = randomSample(iota(arr.length), 9 * arr.length / 10); foreach (s; sample) { arr[s].b = true; arr[s].d = 1.0; } StopWatch watch; size_t i = 0; foreach (a; arr) { watch.start(); if (!a.b) { ++i; } watch.stop(); } writeln("Time for ", arr.length, " if(boolean)'s with ", i, " counts of true: ", watch.peek.usecs, " microseconds."); watch.reset; i = 0; foreach (a; arr) { watch.start(); if (isNaN(a.d)) { ++i; } watch.stop(); } writeln("Time for ", arr.length, " if(isNaN)'s with ", i, " counts of true: ", watch.peek.usecs, " microseconds."); }