diff --git a/index.dd b/index.dd index 39df223634..5d3994a7fd 100644 --- a/index.dd +++ b/index.dd @@ -142,6 +142,25 @@ void main() } ---- ) +$(EXTRA_EXAMPLE_RUNNABLE Initialize an Array in parallel, +---- +void main() +{ + import std.datetime, 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].msecs); + writefln("Parallel init: %s msecs", bm[1].msecs); +} +---- +) ) $(COMMENT your-code-here) ))) $(COMMENT intro, div, div)