Skip to content

Instantly share code, notes, and snippets.

@methane
Created March 9, 2012 00:23
Show Gist options
  • Select an option

  • Save methane/2004315 to your computer and use it in GitHub Desktop.

Select an option

Save methane/2004315 to your computer and use it in GitHub Desktop.
all:
cython --embed mltest.py
gcc -O2 mltest.c `python-config --cflags --ldflags` -fPIC -o mltest
cython --embed mltest2.pyx
gcc -O2 mltest2.c `python-config --cflags --ldflags` -fPIC -o mltest2
# -*- coding: utf-8 -*-
import time
LOOP = 100000000
def fixedPoint(driver):
a, st = 0, time.time()
for i in xrange(LOOP):
if not driver:
a += 1
return time.time() - st
def floatingPoint(driver):
a, st = 0.0, time.time()
for i in xrange(LOOP):
if not driver:
a += 1.0
return time.time() - st
def main():
tm = fixedPoint(0) - fixedPoint(1)
tmc = "%04d" % int(tm + 0.5)
print "<FIXED POINT> ......", tmc, "sec :", LOOP, "times"
tm = floatingPoint(0) - floatingPoint(1)
tmc = "%04d" % int(tm + 0.5)
print "<FLOATING POINT> ...", tmc, "sec :", LOOP, "times"
if __name__ == "__main__":
main()
# -*- coding: utf-8 -*-
import time
LOOP = 100000000
def fixedPoint(bint driver, int loop=LOOP):
cdef long long a = 0
st = time.time()
for i in xrange(loop):
if not driver:
a += 1
return time.time() - st
def floatingPoint(bint driver, int loop=LOOP):
cdef double a = 0
st = time.time()
for i in xrange(loop):
if not driver:
a += 1.0
return time.time() - st
def main():
tm = fixedPoint(0) - fixedPoint(1)
tmc = "%04d" % int(tm + 0.5)
print "<FIXED POINT> ......", tmc, "sec :", LOOP, "times"
tm = floatingPoint(0) - floatingPoint(1)
tmc = "%04d" % int(tm + 0.5)
print "<FLOATING POINT> ...", tmc, "sec :", LOOP, "times"
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment