On 09/19/2011 04:08 PM, Andrei Alexandrescu wrote:
On 9/19/11 6:25 AM, Steven Schveighoffer wrote:
On Sun, 18 Sep 2011 15:34:16 -0400, Timon Gehr <timon.g...@gmx.ch> wrote:

On 09/18/2011 08:28 PM, Andrei Alexandrescu wrote:
That would allow us to e.g. switch from the
pointer+length representation to the arguably better pointer+pointer
representation with ease.

In what way is that representation better?

I agree, I don't see why the representation is inherently better. Some
operations become higher performance (i.e. popFront), and some become
worse (i.e. length). Most of the others are a wash.

That's where frequency of use comes into play. I'm thinking popFront
would be used most often, and it touches two words.

Andrei

Normally, each popFront comes with an accompanying empty, and the comparison against 0 is faster after a decrement than the comparison of two arbitrary pointer values.

Now a benchmark:

import std.datetime, std.stdio;

int[100000] a;

void f1(){
    for(auto ptr=a.ptr, len=a.length+1; len; ++ptr, --len){}
}
void f2(){
    for(auto b=a.ptr, e=a.ptr+a.length; b!=e; b++){}
}

void main(){
    auto b=benchmark!(f1,f2)(100000);
    writeln(b[0].to!("seconds",double)," ", b[1].to!("seconds",double));
}

On my machine: (-O -release -inline)
4.00256 4.00099

The difference is inconceivable on my oldish Core 2 Duo processor. Yet there is a reproducible difference that indicates that you were right about the pointer-pointer representation being slightly faster for that use case.









Reply via email to