Ejemplo n.º 1
0
from pypy.interpreter.error import oefmt
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rtyper.tool import rffi_platform
from rpython.translator.tool.cbuild import ExternalCompilationInfo
import math

time_t = rffi_platform.getsimpletype('time_t', '#include <time.h>', rffi.SIGNED)

eci = ExternalCompilationInfo(includes=['time.h'])
time = rffi.llexternal('time', [lltype.Signed], time_t,
                       compilation_info=eci)

def get(space, name):
    w_module = space.getbuiltinmodule('_demo')
    return space.getattr(w_module, space.newtext(name))


@unwrap_spec(repetitions=int)
def measuretime(space, repetitions, w_callable):
    if repetitions <= 0:
        w_DemoError = get(space, 'DemoError')
        raise oefmt(w_DemoError, "repetition count must be > 0")
    starttime = time(0)
    for i in range(repetitions):
        space.call_function(w_callable)
    endtime = time(0)
    return space.newint(endtime - starttime)
Ejemplo n.º 2
0
def test_simple_type():
    ctype = rffi_platform.getsimpletype('test_t',
                                        'typedef unsigned short test_t;',
                                        rffi.INT)
    assert ctype == rffi.USHORT
Ejemplo n.º 3
0
from pypy.interpreter.error import oefmt
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rtyper.tool import rffi_platform
from rpython.translator.tool.cbuild import ExternalCompilationInfo
import math

time_t = rffi_platform.getsimpletype("time_t", "#include <time.h>", rffi.LONG)

eci = ExternalCompilationInfo(includes=["time.h"])
time = rffi.llexternal("time", [lltype.Signed], time_t, compilation_info=eci)


def get(space, name):
    w_module = space.getbuiltinmodule("_demo")
    return space.getattr(w_module, space.wrap(name))


@unwrap_spec(repetitions=int)
def measuretime(space, repetitions, w_callable):
    if repetitions <= 0:
        w_DemoError = get(space, "DemoError")
        raise oefmt(w_DemoError, "repetition count must be > 0")
    starttime = time(0)
    for i in range(repetitions):
        space.call_function(w_callable)
    endtime = time(0)
    return space.wrap(endtime - starttime)
Ejemplo n.º 4
0
def test_simple_type():
    ctype = rffi_platform.getsimpletype('test_t',
                                        'typedef unsigned short test_t;',
                                        rffi.INT)
    assert ctype == rffi.USHORT
Ejemplo n.º 5
0
from pypy.interpreter.error import OperationError
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rtyper.tool import rffi_platform
from rpython.translator.tool.cbuild import ExternalCompilationInfo
import math

time_t = rffi_platform.getsimpletype('time_t', '#include <time.h>', rffi.LONG)

eci = ExternalCompilationInfo(includes=['time.h'])
time = rffi.llexternal('time', [lltype.Signed], time_t,
                       compilation_info=eci)

def get(space, name):
    w_module = space.getbuiltinmodule('_demo')
    return space.getattr(w_module, space.wrap(name))


@unwrap_spec(repetitions=int)
def measuretime(space, repetitions, w_callable):
    if repetitions <= 0:
        w_DemoError = get(space, 'DemoError')
        msg = "repetition count must be > 0"
        raise OperationError(w_DemoError, space.wrap(msg))
    starttime = time(0)
    for i in range(repetitions):
        space.call_function(w_callable)
    endtime = time(0)
    return space.wrap(endtime - starttime)