diff --git a/.gitignore b/.gitignore index 6b3cb88..43651b9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ Images/ build/ dist/ MANIFEST +profile.data diff --git a/EffectLabProfile.py b/EffectLabProfile.py new file mode 100755 index 0000000..9e58467 --- /dev/null +++ b/EffectLabProfile.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# author: Hua Liang [ Stupid ET ] +# email: et@everet.org +# 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' + diff --git a/TestEffectLab.py b/TestEffectLab.py index 9665d52..534f4d4 100755 --- a/TestEffectLab.py +++ b/TestEffectLab.py @@ -1,9 +1,11 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- # author: Hua Liang [ Stupid ET ] # email: et@everet.org # website: http://EverET.org # + import os, time, string, random import autoreload import ImageChops @@ -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'