From f1bf9ec6331a69a22b231568ee0aad906e1a0b9c Mon Sep 17 00:00:00 2001 From: Cedric Porter Date: Tue, 14 Aug 2012 17:05:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=9A=84=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + EffectLabProfile.py | 37 +++++++++++++++++++++++++++++++++++++ TestEffectLab.py | 21 ++++++++++++++++++--- 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100755 EffectLabProfile.py 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'