Skip to content

Commit 78a360e

Browse files
committed
Reporting for February
1 parent 7246d4d commit 78a360e

File tree

4 files changed

+70
-35
lines changed

4 files changed

+70
-35
lines changed

libsrfit/diffpy/srfit/boost/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
from _visitor import Visitor
99
from _callout import Callout
1010
from _evaluator import Evaluator
11+
12+
from _purespeed import *

libsrfit/diffpy/srfit/boost/module.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ endif
1818

1919
# SrFit headers
2020
ifndef SRFIT_HEADERS
21-
SRFIT_HEADERS=/home/chris/Programming/Pyre/dv/danse/diffraction/diffpy.srfit/trunk/libsrfit/
21+
SRFIT_HEADERS=/home/chris/Programming/Pyre/dv/danse/diffraction/diffpy.srfit/branches/cppequation/libsrfit/
2222
endif
2323

2424
# PYTHON_INCDIR

libsrfit/diffpy/srfit/boost/purespeed_ext.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,27 @@ void speedy()
3232
}
3333
}
3434

35+
bp::object pyspeedy(bp::object& f, bp::list& l)
36+
{
37+
bp::object res = f(l);
38+
return res;
39+
}
40+
41+
bp::object pyspeedy2(bp::object& f, bp::object& o)
42+
{
43+
bp::object res = f(o);
44+
return res;
45+
}
46+
47+
48+
3549
}
3650

3751
BOOST_PYTHON_MODULE(_purespeed)
3852
{
3953

4054
def("speedy", &speedy);
55+
def("pyspeedy", &pyspeedy);
56+
def("pyspeedy", &pyspeedy2);
4157
}
4258

libsrfit/diffpy/srfit/boost/speedtest.py

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ def _makeArgs(num):
1212
args[-1].name = "v%i"%(i+1,)
1313
return args
1414

15-
x = numpy.arange(0, 20, 0.05)
1615

1716

1817
class AdditionOperator(UFuncOperator):
@@ -132,6 +131,15 @@ def _f(a, b, c):
132131

133132
return _f
134133

134+
def makeTrunkEquation():
135+
from diffpy.srifit.equation.builder import EquationFactory
136+
f = EquationFactory()
137+
138+
f.registerConstant("x", x)
139+
140+
eq = f.makeEquation("(v1+x)*(50*x-v4))**2.11 * e**v7")
141+
return eq
142+
135143
def makeEquation():
136144
"""Make the same equation as the lazy one."""
137145

@@ -150,50 +158,59 @@ def timeFunction(f, *args):
150158
t2 = time.time()
151159
return (t2-t1)*1000
152160

153-
if __name__ == "__main__":
154161

155-
f1 = makeLazyEquation()
156-
f2 = makeEquation()
162+
def test(mutate):
157163

158-
a, b, c = 3.1, 8.19973123410, 2.1
159-
160-
t1 = timeFunction(f1, a, b, c)
161-
t2 = timeFunction(f2, a, b, c)
162-
print "Initial"
163-
print "lazy", t1
164-
print "regular", t2
164+
numtrials = 1000
165165

166166
import time
167167
import _purespeed
168168
t1 = time.time()
169169
_purespeed.speedy()
170170
t2 = time.time()
171-
print "Pure Speed", (t2-t1)*1000
171+
print "Pure c++", (t2-t1)*1000
172+
print
172173

174+
f0 = makeLazyEquation()
175+
f1 = makeLazyEquation()
176+
f2 = makeEquation()
173177

174-
# Change one of the variables
175-
b = 10.1
176-
t1 = timeFunction(f1, a, b, c)
177-
t2 = timeFunction(f2, a, b, c)
178-
print "Single change"
179-
print "lazy", t1
180-
print "regular", t2
178+
args = [3.1, 8.19973123410, 2.1]
181179

182-
# Change two
183-
a = 2.0
184-
b = 2.0
185-
t1 = timeFunction(f1, a, b, c)
186-
t2 = timeFunction(f2, a, b, c)
187-
print "Two change"
188-
print "lazy", t1
189-
print "regular", t2
180+
t0 = 0
181+
t1 = 0
182+
t2 = 0
183+
184+
import random
185+
for i in xrange(numtrials):
186+
187+
c = range(len(args))
188+
189+
for j in range(mutate):
190+
k = random.choice(c)
191+
c.remove(k)
192+
args[k] = random.uniform(0, 10)
193+
194+
t0 += timeFunction(f0, *args)
195+
t1 += timeFunction(f1, *args)
196+
t2 += timeFunction(f2, *args)
197+
198+
t0 /= numtrials
199+
t1 /= numtrials
200+
t2 /= numtrials
190201

191-
# Change three
192-
a = 1.0
193-
b = 1.0
194-
c = 1.0
195-
t1 = timeFunction(f1, a, b, c)
196-
t2 = timeFunction(f2, a, b, c)
197-
print "Three change"
202+
print "Mutate %i (%i trials averaged)" % (mutate, numtrials)
203+
print "trunk", t0
198204
print "lazy", t1
199205
print "regular", t2
206+
print
207+
208+
209+
210+
211+
if __name__ == "__main__":
212+
213+
x = numpy.arange(0, 20, 0.05)
214+
test(1)
215+
test(2)
216+
test(3)

0 commit comments

Comments
 (0)