Why Strings as Classes?

bearophile bearophileHUGS at lycos.com
Tue Aug 26 17:33:29 PDT 2008


Walter Bright:

>In my experience with such programs, disabling the collection cycles brought the speed up to par.<

In my experience there's some difference still.
The usual disclaimer: benchmarks are tricky things, so anyone is invited to spot problems in my code.


A very simple benchmark:

// D without GC
import std.gc: disable;
void main() {
    int[int] d;
    disable();
    for (int i; i < 10_000_000; ++i)
        d[i] = 0;
}


# Python+Psyco without GC
from gc import disable
def main():
    d = {}
    disable()
    for i in xrange(10000000):
        d[i] = 0
import psyco; psyco.full()
main()


hash without GC, n = 10_000_000:
  D:     9.12 s
  Psyco: 1.45 s

hash2 with GC, n = 10_000_000:
  D:     9.80 s
  Psyco: 1.46 s


If Psyco isn't used the Python version without GC requires 2.02 seconds. This means the 2.02 - 1.45 = 0.57 s are needed by the Python virtual machine just to run those 10_000_000 loops :-)

Warms tests, best of 3, tests performed with Python 2.5.2, Psyco 1.6, on Win XP, and the last DMD with -O -release -inline.

Python integers are objects, rather bigger than 4 bytes, and they can grow "naturally" to become multi-precision integers:

>>> a = 2147483647
>>> a
2147483647
>>> a + 1
2147483648L
>>> type(a)
<type 'int'>
>>> type(a + 1)
<type 'long'>
>>> type(7 ** 5)
<type 'int'>
>>> type(7 ** 55)
<type 'long'>

Bye,
bearophile



More information about the Digitalmars-d mailing list