[pypy-dev] PyPy is faster than CPython (given an evil enough benchmark)

Carl Friedrich Bolz cfbolz at gmx.de
Fri Jul 7 14:03:17 CEST 2006

Hi all!

Together with the optimized string objects that Armin, Pieter,
Alexander and me have been working on, it is possible to construct a
(very corner-casish) benchmark, which exploits the fast cases of PyPy
in such a way, that it is quite a bit faster CPython. See the
following code:

import time, sys

def test_speed(num):
    t1 = time.time()
    result = ""
    intermediate = []
    for i in range(num):
        result += str(i)
    t2 = time.time()
    return t2 - t1, intermediate

t1 = time.time()
for i in range(1, 12):
    speed, intermediate = test_speed(i * 1000)
t2 = time.time()
print t2 - t1

It runs 3.4 times faster on pypy-c with WITHSTRSLICE = WITHSTRJOIN =
True. In addition CPython uses 25 times more memory (which of course
accounts for some of the slowness).

Of course the lesson of this is that benchmarks are worthless :-).


Carl Friedrich

More information about the Pypy-dev mailing list