def test_use_car_move(self): tyctx = typing.Context() tyctx.insert_class(Car, self.carattrs) cgctx = CPUContext(tyctx) cgctx.insert_class(Car, self.carattrs) car_object = types.Object(Car) argtys = (car_object, types.int32) flags = compiler.Flags() cr = compiler.compile_extra(tyctx, cgctx, use_car_move, args=argtys, return_type=None, flags=flags, locals={}) func = cr.entry_point if cr.typing_error: raise cr.typing_error car1 = Car(value=123) car2 = Car(value=123) self.assertEqual(use_car_move(car1, 321), func(car2, 321)) def bm_python(): use_car_move(car1, 321) def bm_numba(): func(car2, 321) python = utils.benchmark(bm_python, maxsec=.1) numba = utils.benchmark(bm_numba, maxsec=.1) print(python) print(numba)
def setUp(self): move_signature = typing.signature(types.none, types.int32, recvr=types.Object(Car)) carattrs = { "value": types.int32, "move" : typing.new_method(Car.move, move_signature), } self.carattrs = carattrs
def insert_class(self, cls, attrs): clsty = types.Object(cls) for name, vtype in utils.dict_iteritems(attrs): imp = python_attr_impl(clsty, name, vtype) self.attrs[imp.key] = imp
def insert_class(self, cls, attrs): clsty = types.Object(cls) for name, vtype in utils.iteritems(attrs): imp = python_attr_impl(clsty, name, vtype) self.attrs[imp.attr].append(imp)
def insert_class(self, cls, attrs): clsty = types.Object(cls) at = templates.ClassAttrTemplate(self, clsty, attrs) self.insert_attributes(at)