annotate python/pydc/examples/sintest.py @ 33:ba47a3d709d7

- pydc: added support to get libhandle's path
author Tassilo Philipp
date Sat, 11 Apr 2020 20:00:25 +0200
parents edbbd467f50a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 import math
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 import os
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 import pydc
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
4 import sys
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
5 import platform
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
6
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
7 if sys.platform == "win32":
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
8 libm = pydc.load("msvcrt")
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
9 elif sys.platform == "darwin":
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
10 libm = pydc.load("/usr/lib/libm.dylib")
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
11 elif "bsd" in sys.platform:
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
12 libm = pydc.load("/usr/lib/libm.so")
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
13 elif platform.architecture()[0] == "64bit":
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
14 libm = pydc.load("/lib64/libm.so.6")
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
15 else:
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
16 libm = pydc.load("/lib/libm.so.6")
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
17
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
18 fp_sin = pydc.find(libm,"sin")
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
19
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
20
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 def f1(n):
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
23 x = 0
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
24 while x < n:
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 math.sin(x)
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
26 x += 1
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 # filter( math.sin, range(0,n) )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
29 #def libmsin(x): pass
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 def f2(n):
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
32 x = 0
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
33 while x < n:
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
34 pydc.call(fp_sin,"d)d",float(x))
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
35 x += 1
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
36 # libmsin(i)
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
38 # filter( libmsin , range(0,n) )
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
41 print("start_native "+str(os.times()))
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 f1(10000000)
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
43 print("start_dc "+str(os.times()))
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
44 f2(10000000)
28
edbbd467f50a python binding:
Tassilo Philipp
parents: 5
diff changeset
45 print("end "+str(os.times()))
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46