Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created January 10, 2022 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save run-dlang/fcbab4a73935c10d2f28f5dc4b1d3775 to your computer and use it in GitHub Desktop.
Save run-dlang/fcbab4a73935c10d2f28f5dc4b1d3775 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io. Run with '-unittest'
void main()
{
import std.datetime.stopwatch : benchmark;
import std.math, std.parallelism, std.stdio;
auto logs = new double[100_000];
auto bm = benchmark!({
foreach (i, ref elem; logs)
elem = log(1.0 + i);
}, {
foreach (i, ref elem; logs.parallel)
elem = log(1.0 + i);
})(100); // number of executions of each tested function
writefln("Linear init: %s msecs", bm[0].total!"msecs");
writefln("Parallel init: %s msecs", bm[1].total!"msecs");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment