cimport cython
import time
cdef class Bench:
cdef int n0
def __init__(self):
self.n0 = 0
@cython.nonecheck(False)
cdef int calc(self, int n):
cdef int n1 = self.n0 + (1 - 2 * (n % 2))
self.n0 = n
return n1
def main():
# Declaration
cdef int i = 0
cdef int n = 1
# Instantiation
obj_bench = Bench()
# Main Process
t1 = time.time()
while i < 2147483647:
n = obj_bench.calc(n)
i += 1
t2 = time.time()
print("Cython\t-> %8.4f secs." %(t2 - t1))
Y2ltcG9ydCBjeXRob24KaW1wb3J0IHRpbWUKCmNkZWYgY2xhc3MgQmVuY2g6CiAgICBjZGVmIGludCBuMAogICAgZGVmIF9faW5pdF9fKHNlbGYpOgogICAgICAgIHNlbGYubjAgPSAwCgogICAgQGN5dGhvbi5ub25lY2hlY2soRmFsc2UpCiAgICBjZGVmIGludCBjYWxjKHNlbGYsIGludCBuKToKICAgICAgICBjZGVmIGludCBuMSA9IHNlbGYubjAgKyAoMSAtIDIgKiAobiAlIDIpKQogICAgICAgIHNlbGYubjAgPSBuCiAgICAgICAgcmV0dXJuIG4xCgpkZWYgbWFpbigpOgogICAgIyBEZWNsYXJhdGlvbgogICAgY2RlZiBpbnQgaSA9IDAKICAgIGNkZWYgaW50IG4gPSAxCgogICAgIyBJbnN0YW50aWF0aW9uCiAgICBvYmpfYmVuY2ggPSBCZW5jaCgpCgogICAgIyBNYWluIFByb2Nlc3MKICAgIHQxID0gdGltZS50aW1lKCkKICAgIHdoaWxlIGkgPCAyMTQ3NDgzNjQ3OgogICAgICAgIG4gPSBvYmpfYmVuY2guY2FsYyhuKQogICAgICAgIGkgKz0gMQogICAgdDIgPSB0aW1lLnRpbWUoKQogICAgcHJpbnQoIkN5dGhvblx0LT4gJTguNGYgc2Vjcy4iICUodDIgLSB0MSkp
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'))