Guest User

Untitled

a guest
Dec 22nd, 2010
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. // D version, with std.algorithm
  2. // ~ 281 ms, using dmd 2.051 (dmd -O -release -inline)
  3.  
  4. import std.algorithm;
  5. import std.stdio;
  6. import std.range;
  7.  
  8. void main() {
  9.     auto L = iota(0.0, 10000000.0);
  10.  
  11.     auto L2 = map!"a / 2"(L);
  12.     auto L3 = map!"a + 2"(L2);
  13.     //using the reduce form with a seed makes it slower by ~25%, why?
  14.     auto V = reduce!"a + b"(L3);
  15.  
  16.     //using proper delegate literals makes it slower! (program runs in ~ 314 ms)
  17.     /+
  18.     auto L2 = map!((a) { return a / 2; })(L);
  19.     auto L3 = map!((a) { return a + 2; })(L2);
  20.     auto V = reduce!((a, b) { return a + b; })(L3);
  21.     +/
  22.  
  23.     writefln("%f", V);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment