fix race condition by Michael J Gruber
[PyX/mjg.git] / test / profile_path.py
blob797867c792736ca431199700b215c02ef6201b54
1 #!/usr/bin/env python
2 import sys
3 sys.path[:0] = [".."]
5 import pyx
6 from pyx import *
7 from pyx.path import *
10 def testspeed():
11 "coordinates as strings"
13 c=canvas.canvas()
14 p=path(moveto(0,0))
16 for i in xrange(1000):
17 p.append(lineto("%d pt" % i, "%d pt" % i))
19 c.stroke(p)
20 c.writeEPSfile("testspeed")
22 def testspeed2():
23 "coordinates in user units"
25 c=canvas.canvas()
26 p=path(moveto(0,0))
28 for i in xrange(1000):
29 p.append(lineto(i,i))
31 c.stroke(p)
32 c.writeEPSfile("testspeed")
34 def testspeed3():
35 "coordinates in pts (internal routines)"
37 c=canvas.canvas()
38 p=path(pyx.path.moveto_pt(0,0))
40 for i in xrange(1000):
41 p.append(pyx.path.lineto_pt(i, i))
43 c.stroke(p)
44 c.writeEPSfile("testspeed")
46 def testspeedintersect():
47 p=path(moveto(10,10), curveto(12,16,14,15,12,19))
48 bp=normpath(p)
50 for x in xrange(1,100):
51 q=path(moveto(x/5.0,10), curveto(12,16,14,22,11,16))
52 bq=normpath(q)
53 isect = bp.intersect(bq, epsilon=1e-3)
55 import profile, pstats
57 import hotshot, hotshot.stats
59 def profilefunction(f):
60 prof = hotshot.Profile("test.prof")
61 prof.runcall(f)
62 prof.close()
63 stats = hotshot.stats.load("test.prof")
64 stats.strip_dirs()
65 stats.sort_stats('time', 'calls')
66 stats.print_stats(10)
68 profile.run('testspeed()', 'test.prof')
69 pstats.Stats("test.prof").sort_stats('time').print_stats(10)
71 profilefunction(testspeed)
73 #profile.run('testspeed2()', 'test.prof')
74 #pstats.Stats("test.prof").sort_stats('time').print_stats(10)
76 #profile.run('testspeed3()', 'test.prof')
77 #pstats.Stats("test.prof").sort_stats('time').print_stats(10)
79 #profile.run('testspeedintersect()', 'test.prof')
80 #pstats.Stats("test.prof").sort_stats('time').print_stats(10)