Created
January 10, 2022 14:28
-
-
Save run-dlang/fcbab4a73935c10d2f28f5dc4b1d3775 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io. Run with '-unittest'
This file contains 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
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