annotate python/pydc/examples/sintest.py @ 18:3bfef07b0cd9

- cleanup of non-working java binding, restart work, somewhat different interface
author cslag
date Wed, 30 Mar 2016 02:05:06 +0200
parents bf5625bb6f05
children edbbd467f50a
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
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
18 fpsin = pydc.find(libm,"sin")
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):
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23 for x in xrange(n):
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 math.sin(x)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 # filter( math.sin, range(0,n) )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
27 def libmsin(x): pass
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 def f2(n):
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 for x in xrange(n):
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 pydc.call(fpsin,"d)d",float(x))
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
32 # libmsin(i)
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
34 # filter( libmsin , range(0,n) )
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
37 print "start_native"+str(os.times())
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38 f1(10000000)
5
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
39 print "start_dc"+str(os.times())
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
40 f2(10000000)
bf5625bb6f05 - brought python binding up to dc v0.9
cslag
parents: 0
diff changeset
41 print "end"+str(os.times())
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42