def test_for_loop2(self): clean("test_cython_compile_CyTest2") CyTest2(1) res1, t_cy = get_time(CyTest2)(10000000) res2, t_py = get_time(PyTest2)(10000000) self.assertTrue(res1, res2) self.assertTrue(t_cy * 20 < t_py, "20*%s=%s not < %s" % (t_cy, 20 * t_cy, t_py))
def test_for_loop(self): clean("test_cython_compile_autodeclare_CyTest2") CyTest2(1) res1, t_cy = get_time(CyTest2)(10000000) res2, t_py = get_time(PyTest2)(10000000) self.assertTrue(res1, res2) self.assertTrue(t_cy * 20 < t_py, "t_cy, t_py: %s, %s" % (t_cy, t_py))
def compare(self, module_name, func, *args): clean(module_name) with open(module_name + '.py', 'w') as fid: fid.write(inspect.getsource(func)) res1, t_py = get_time(func)(*args) cython_import(module_name) cmodule = __import__(module_name) cfunc = getattr(cmodule, func.func_name) res2, t_cy = get_time(cfunc)(*args) self.assertEqual(res1, res2, "%s - %s" % (module_name, func)) clean(module_name) return t_py, t_cy
def test_for_loop(self): clean("test_cython_compile_CyTest1") CyTest1(1) _, t_cy = get_time(CyTest1)(10000000) _, t_py = get_time(PyTest1)(10000000) self.assertTrue(t_cy * 2 < t_py)