AA performance again

bearophile bearophileHUGS at lycos.com
Mon Jun 9 15:02:00 PDT 2008


Walter Bright:

> Python uses 32 bit integers, so the equivalent D AA would be:
> 	size_t[int] aa;
> D longs are 64 bits.

As usual you are right and I am wrong :-)
My purpose is to have a good language to use, and you can see I like D :-) (I conflate AAs into the language because they are built in).

Python 2.5 uses 32 signed numbers by default, but they are objects, and they are converted to multiprecision numbers whenever necessary:

>>> a = 2147483647
>>> type(a)
<type 'int'>
>>> b = a + 1
>>> b
2147483648L
>>> type(b)
<type 'long'>

In Python 3 all numbers will be longs (at the moment they are about 25-30% slower, I think, but Python 3 is in beta still).

------------------

I have tested with uints then (no GC), the new D code:

import std.conv: toUint;
import std.gc: disable, enable;
void main(string[] args) {
    uint n = toUint(args[1]);
    size_t[uint] aa;
    disable;
    for (uint i; i < n; ++i)
        aa[i] = 0;
    enable;
}

The timings seem the same:
1_000_000     0.27 s
2_000_000     0.59 s
5_000_000     2.14 s
10_000_000    8.87 s
20_000_000   29.9  s

If someone can confirm such timings...

Bye and thank you,
bearophile



More information about the Digitalmars-d mailing list