ranges

Ellery Newcomer ellery-newcomer at utulsa.edu
Thu Apr 29 11:52:55 PDT 2010


Hello.

I'm muddling over the following code, which compares an array/take 
composition with the analogous imperative code. For medium-large values 
of n, I'm seeing a fivefold degradation in performance, which blows up 
to 30 times worse at n=50000000.

Any ideas on why this is or better ways to accomplish the same?

import std.range;
import std.date;
import std.random;
import std.array;
import std.stdio;

void main(){
     for(int n = 500; n <= 500000000; n *= 10){
         writeln(n);
         auto r = rndGen();
         auto tz = getUTCtime();
         auto a = new int[n];
         foreach(ref aa; a){
             aa = r.front();
             r.popFront();
         }
         auto tz2 = getUTCtime();
         auto a2 = array(take(r,n));
         auto tz3 = getUTCtime();
         writeln("\tarr: ",tz2-tz);
         writeln("\trange: ",tz3-tz2);
     }
}
~


More information about the Digitalmars-d-learn mailing list