Skip to content

Commit

Permalink
增加了性能测试的代码。
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricporter committed Aug 14, 2012
1 parent 81182d3 commit f1bf9ec
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Images/
build/
dist/
MANIFEST
profile.data
37 changes: 37 additions & 0 deletions EffectLabProfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: Hua Liang [ Stupid ET ]
# email: [email protected]
# website: http://EverET.org
#

import os
from EffectLab.Effect import *

Effect.empty_color = (255, 255, 255, 255)

if __name__ == '__main__':
from timeit import Timer
from functools import partial
import cProfile

img = Image.new("RGB", (100, 100))
wave = GlobalWaveEffect(1, 0.5)
test = partial(wave, img)

profile = False
if profile:
cProfile.run("test()", "profile.data")

import pstats
#创建Stats对象
p = pstats.Stats("profile.data")
# p.strip_dirs().sort_stats(-1).print_stats()
# p.strip_dirs().sort_stats("cumulative").print_stats()
p.strip_dirs().sort_stats("time").print_stats()
else:
t = Timer('test()', 'from __main__ import test')
N = 3
TIMES = 30
print sum(t.repeat(N, TIMES)) / N / TIMES * 1000, 'ms'

21 changes: 18 additions & 3 deletions TestEffectLab.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: Hua Liang [ Stupid ET ]
# email: [email protected]
# website: http://EverET.org
#


import os, time, string, random
import autoreload
import ImageChops
Expand Down Expand Up @@ -92,12 +94,25 @@ def main():
# main()
from timeit import Timer
from functools import partial
import cProfile

img = Image.new("RGB", (100, 100))
wave = GlobalWaveEffect(1, 0.5)
test = partial(wave, img)

t = Timer('test()', 'from __main__ import test')

print sum(t.repeat(3, 100)) / 3
profile = False
if profile:
cProfile.run("test()", "profile.data")

import pstats
#创建Stats对象
p = pstats.Stats("profile.data")
# p.strip_dirs().sort_stats(-1).print_stats()
# p.strip_dirs().sort_stats("cumulative").print_stats()
p.strip_dirs().sort_stats("time").print_stats()
else:
t = Timer('test()', 'from __main__ import test')
N = 3
TIMES = 30
print sum(t.repeat(N, TIMES)) / N / TIMES * 1000, 'ms'

0 comments on commit f1bf9ec

Please sign in to comment.