Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // D version, with std.algorithm
- // ~ 281 ms, using dmd 2.051 (dmd -O -release -inline)
- import std.algorithm;
- import std.stdio;
- import std.range;
- void main() {
- auto L = iota(0.0, 10000000.0);
- auto L2 = map!"a / 2"(L);
- auto L3 = map!"a + 2"(L2);
- //using the reduce form with a seed makes it slower by ~25%, why?
- auto V = reduce!"a + b"(L3);
- //using proper delegate literals makes it slower! (program runs in ~ 314 ms)
- /+
- auto L2 = map!((a) { return a / 2; })(L);
- auto L3 = map!((a) { return a + 2; })(L2);
- auto V = reduce!((a, b) { return a + b; })(L3);
- +/
- writefln("%f", V);
- }
Advertisement
Add Comment
Please, Sign In to add comment