~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to pypy/translator/tool/benchmark.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import autopath
 
2
from pypy.tool import testit
 
3
from pypy.tool.udir import udir
 
4
from pypy.translator.tool.cbuild import build_cfunc
 
5
from pypy.translator.test.test_cltrans import global_cl, make_cl_func
 
6
 
 
7
def benchmark(func):
 
8
    try:
 
9
        func = func.im_func
 
10
    except AttributeError:
 
11
        pass
 
12
    c_func = build_cfunc(func, dot=False)
 
13
    if global_cl:
 
14
        cl_func = make_cl_func(func)
 
15
    print "generated c-func for", func.func_name
 
16
    t1 = timeit(100, func)
 
17
    t2 = timeit(100, c_func)
 
18
    if global_cl:
 
19
        t3 = timeit(100, cl_func)
 
20
    print "cpython func       ", t1, "seconds"
 
21
    print "pypy/pyrex/cmodule ", t2, "seconds"
 
22
    if global_cl:
 
23
        print "cl (experimental)  ", t3, "seconds", global_cl
 
24
   
 
25
def timeit(num, func, *args):
 
26
    from time import time as now
 
27
    start = now()
 
28
    for i in xrange(num):
 
29
        func(*args)
 
30
    return now()-start
 
31
 
 
32
if __name__ == '__main__':
 
33
    from pypy.translator.test.snippet import sieve_of_eratosthenes
 
34
    benchmark(sieve_of_eratosthenes)