forked from notmyname/python_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptimize_test.py
43 lines (32 loc) · 824 Bytes
/
optimize_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python2.4
# not a good test because the function is fast anyway (not a lot of globals to be re-referenced)
from optimize import make_constants
from Common import logged_function
hole = open('/dev/null','w')
class klass(object):
def write(*args):
for a in args: print >>hole, a
obj = klass()
@logged_function(when='post')
def slow():
for i in range(10000):
obj.write('hello world')
@logged_function(when='post')
@make_constants
def fast():
for i in range(10000):
obj.write('hello world')
def main():
slow()
fast()
import profile,pstats
profile.run('main()','optimize_results')
s = pstats.Stats('optimize_results')
s.sort_stats('time','cumulative')
s.print_stats()
import dis
print 'slow() disassebly:'
print dis.dis(slow)
print
print 'fast() disassembly:'
print dis.dis(fast)