| 1 |
void main() |
| 2 |
{ |
| 3 |
import std.datetime.stopwatch : benchmark; |
| 4 |
import std.math, std.parallelism, std.stdio; |
| 5 |
|
| 6 |
auto logs = new double[100_000]; |
| 7 |
auto bm = benchmark!({ |
| 8 |
foreach (i, ref elem; logs) |
| 9 |
elem = log(1.0 + i); |
| 10 |
}, { |
| 11 |
foreach (i, ref elem; logs.parallel) |
| 12 |
elem = log(1.0 + i); |
| 13 |
})(100); // number of executions of each tested function |
| 14 |
writefln("Linear init: %s msecs", bm[0].total!"msecs"); |
| 15 |
writefln("Parallel init: %s msecs", bm[1].total!"msecs"); |
| 16 |
} |
| 17 |
|
| 18 |
// From https://dlang.org/ |