Created
March 9, 2012 00:23
-
-
Save methane/2004315 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- 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