comparison python/pydc/examples/sintest.py @ 5:bf5625bb6f05

- brought python binding up to dc v0.9
author cslag
date Tue, 22 Mar 2016 01:49:34 +0100
parents 0cfcc391201f
children edbbd467f50a
comparison
equal deleted inserted replaced
4:4c5019f00f5b 5:bf5625bb6f05
1 import math 1 import math
2 import os 2 import os
3 import pydc 3 import pydc
4 import sys
5 import platform
6
7 if sys.platform == "win32":
8 libm = pydc.load("msvcrt")
9 elif sys.platform == "darwin":
10 libm = pydc.load("/usr/lib/libm.dylib")
11 elif "bsd" in sys.platform:
12 libm = pydc.load("/usr/lib/libm.so")
13 elif platform.architecture()[0] == "64bit":
14 libm = pydc.load("/lib64/libm.so.6")
15 else:
16 libm = pydc.load("/lib/libm.so.6")
17
18 fpsin = pydc.find(libm,"sin")
19
20
4 21
5 def f1(n): 22 def f1(n):
6 for x in xrange(n): 23 for x in xrange(n):
7 math.sin(x) 24 math.sin(x)
8 # filter( math.sin, range(0,n) ) 25 # filter( math.sin, range(0,n) )
9 26
10 27 def libmsin(x): pass
11 libc = pydc.load("msvcrt")
12 fpsin = pydc.find(libc,"sin")
13
14 def libcsin(x): pass
15 28
16 def f2(n): 29 def f2(n):
17 for x in xrange(n): 30 for x in xrange(n):
18 pydc.call(fpsin,"d)d",float(x)) 31 pydc.call(fpsin,"d)d",float(x))
19 # libcsin(i) 32 # libmsin(i)
20 33
21 # filter( libcsin , range(0,n) ) 34 # filter( libmsin , range(0,n) )
22 35
23 36
24 #b = os.times() 37 print "start_native"+str(os.times())
25 f1(10000000) 38 f1(10000000)
26 #f2(10000000) 39 print "start_dc"+str(os.times())
27 e = os.times() 40 f2(10000000)
41 print "end"+str(os.times())
28 42
29 print e
30
31
32
33