-
-
Save Xophmeister/3011398 to your computer and use it in GitHub Desktop.
Branch Prediction Benchmarking in D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio, std.random, core.time; | |
void main() { | |
int data[32768]; | |
foreach(ref x; data) | |
x = uniform(0, 256); | |
data.sort; | |
ulong sum; | |
auto start = TickDuration.currSystemTick(); | |
for(auto i = 0; i < 100000; ++i) | |
foreach(x; data) | |
if (x >= 128) | |
sum += x; | |
writeln("Done in ", (TickDuration.currSystemTick() - start).msecs(), "ms"); | |
writeln("sum = ", sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by this question on StackOverflow:
Compiled with
-O -release
under dmd 2.057 (Win32) on Intel Core2 6420 @ 2.13GHz