0
|
1 import math
|
|
2 import os
|
|
3 import pydc
|
5
|
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
|
28
|
18 fp_sin = pydc.find(libm,"sin")
|
5
|
19
|
|
20
|
0
|
21
|
|
22 def f1(n):
|
28
|
23 x = 0
|
|
24 while x < n:
|
0
|
25 math.sin(x)
|
28
|
26 x += 1
|
0
|
27 # filter( math.sin, range(0,n) )
|
|
28
|
28
|
29 #def libmsin(x): pass
|
0
|
30
|
|
31 def f2(n):
|
28
|
32 x = 0
|
|
33 while x < n:
|
|
34 pydc.call(fp_sin,"d)d",float(x))
|
|
35 x += 1
|
5
|
36 # libmsin(i)
|
0
|
37
|
5
|
38 # filter( libmsin , range(0,n) )
|
0
|
39
|
|
40
|
28
|
41 print("start_native "+str(os.times()))
|
0
|
42 f1(10000000)
|
28
|
43 print("start_dc "+str(os.times()))
|
5
|
44 f2(10000000)
|
28
|
45 print("end "+str(os.times()))
|
0
|
46
|