[phobos] enforce() in std.container.Array

David Simcha dsimcha at gmail.com
Fri Nov 19 05:55:52 PST 2010


I'm looking to try out std.container.Array for a few huge arrays that 
the GC isn't cutting it for.  I noticed that this container is always 
bounds checked via enforce().  This has huge performance costs:

import std.stdio, std.container, std.datetime;

void main() {
     Array!uint arr;
     arr.length = 10_000_000;
     //auto arr = new uint[10_000_000];
     auto sw = StopWatch(autoStart);
     foreach(i; 0..arr.length) {
         arr[i] = i;
     }

     writeln(sw.peek.milliseconds);
}

This benchmark takes about 86 milliseconds with -O -inline -release.  
When I use the builtin version instead (comment out the 
std.container.Array stuff and uncomment the uint[] stuff) it only takes 
about 18 milliseconds.  Should I change front(), popFront(), opIndex(), 
etc. to be templates that use assert and give the caller's line and file 
on failure, just like regular builtin arrays?


More information about the phobos mailing list