fork(15) download
  1. cimport cython
  2. import time
  3.  
  4. cdef class Bench:
  5. cdef int n0
  6. def __init__(self):
  7. self.n0 = 0
  8.  
  9. @cython.nonecheck(False)
  10. cdef int calc(self, int n):
  11. cdef int n1 = self.n0 + (1 - 2 * (n % 2))
  12. self.n0 = n
  13. return n1
  14.  
  15. def main():
  16. # Declaration
  17. cdef int i = 0
  18. cdef int n = 1
  19.  
  20. # Instantiation
  21. obj_bench = Bench()
  22.  
  23. # Main Process
  24. t1 = time.time()
  25. while i < 2147483647:
  26. n = obj_bench.calc(n)
  27. i += 1
  28. t2 = time.time()
  29. print("Cython\t-> %8.4f secs." %(t2 - t1))
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/py_compile.py", line 117, in compile
    raise py_exc
py_compile.PyCompileError: SyntaxError: ('invalid syntax', ('prog.py', 1, 14, 'cimport cython\n'))

stdout
Standard output is empty