[ctypes-commit] ctypes/unittests/com test_perf.py,1.1,1.2
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2005-02-16 20:40:32
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5422 Modified Files: test_perf.py Log Message: It's in better shape now. And includes some figures. Index: test_perf.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/com/test_perf.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_perf.py 16 Feb 2005 18:31:32 -0000 1.1 --- test_perf.py 16 Feb 2005 20:40:20 -0000 1.2 *************** *** 1,14 **** ! # Some preformance measurements ! def test(*args): from timeit import main ! print args[-1] main(args) - print ! from ctypes.com.client import Dispatch ! d = Dispatch("InternetExplorer.Application") ! fd = d.Navigate.fd from ctypes import * class POINT(Structure): --- 1,22 ---- ! import sys, re ! # Some preformance measurements ! def timeit(*args): from timeit import main ! from cStringIO import StringIO ! ! prev_stdout = sys.stdout ! sys.stdout = StringIO() ! main(args) ! out = sys.stdout.getvalue() ! sys.stdout = prev_stdout ! match = re.search(r"(\d+\.\d*|\d+) usec", out) ! time = float(match.group(1)) ! print "%8.2f: %s" % (time, args[-1]) + ################################################################ + import ctypes from ctypes import * class POINT(Structure): *************** *** 21,88 **** pass if __name__ == "__main__": ! # 0.382 us ! test("-s", "from test_perf import Class", "Class()") ! # 1.38 us ! test("-s", "from test_perf import POINT", "POINT()") ! # 1.43 us ! test("-s", "from test_perf import RECT", "RECT()") ! ! import sys ! sys.exit() ! ! # 0.238 us ! test("-s", "from test_perf import POINT; pt = POINT()", ! "pt.y") ! ! # 2.37 us ! test("-s", "from test_perf import RECT; rc = RECT()", ! "rc.lr") ! ! # 6.72 us ! test("-s", "from test_perf import fd", "fd.lprgelemdescParam") ! ! # 10.4 us = 6.72 us + 3.68 us ! test("-s", "from test_perf import fd", "fd.lprgelemdescParam[0]") ! ! # 10.4 us = 6.72 us + 3.68 us ! test("-s", "from test_perf import fd", "fd.lprgelemdescParam[1]") ! ! # 13.2 us = 10.u us + 2.80 us ! test("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc") ! ! # 14 us = 13.2 + 0.8 us ! test("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc.vt") ! ! # 20.7 us = 14 us + 6.7 us ! test("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc.u.lptdesc[0].vt") ! # 1.12 us ! test('-s', "from ctypes import c_int", "c_int()") ! # 1.33 us ! test('-s', "from ctypes import c_int", "c_int(42)") ! # 2.46 us ! test('-s', "from ctypes.com.automation import VARIANT", "VARIANT()") ! ! # 5.41 us ! test('-s', "from ctypes.com.automation import VARIANT; v = VARIANT(3)", "v.value") ! ! # 5.27 us ! test('-s', "from comtypes.automation import VARIANT; v = VARIANT(3)", "v.value") ! # 11.7 us ! test('-s', "from ctypes.com.automation import VARIANT; v = VARIANT()", "v.value = 3.14") - # 13.3 us - test('-s', "from comtypes.automation import VARIANT; v = VARIANT()", "v.value = 3.14") --- 29,128 ---- pass + # get a FUNCDESC instance + from ctypes.com.client import Dispatch + d = Dispatch("InternetExplorer.Application") + fd = d.Navigate.fd + + ################################################################ + if __name__ == "__main__": ! print "ctypes version:", ctypes.__version__ ! print "python version:", sys.version ! ! timeit("-s", "from test_perf import Class", "Class()") ! timeit("-s", "from test_perf import POINT", "POINT()") ! timeit("-s", "from test_perf import RECT", "RECT()") ! timeit("-s", "from test_perf import POINT; point = POINT()", ! "point.y") ! timeit("-s", "from test_perf import RECT; rect = RECT()", ! "rect.lr") ! timeit("-s", "from test_perf import fd", "fd.lprgelemdescParam") ! timeit("-s", "from test_perf import fd", "fd.lprgelemdescParam[0]") ! timeit("-s", "from test_perf import fd", "fd.lprgelemdescParam[1]") ! timeit("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc") ! timeit("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc.vt") ! timeit("-s", "from test_perf import fd", "fd.lprgelemdescParam[1].tdesc.u.lptdesc[0].vt") + timeit('-s', "from ctypes import c_int", + "c_int()") + timeit('-s', "from ctypes import c_int", + "c_int(42)") + timeit('-s', "from ctypes.com.automation import VARIANT", + "VARIANT() # ctypes.com") + timeit('-s', "from ctypes.com.automation import VARIANT; variant = VARIANT(3)", + "variant.value # ctypes.com") + timeit('-s', "from ctypes.com.automation import VARIANT; variant = VARIANT()", + "variant.value = 3.14 # ctypes.com") + try: + import comtypes + except ImportError: + sys.exit() + timeit('-s', "from comtypes.automation import VARIANT", + "VARIANT() # comtypes") + timeit('-s', "from comtypes.automation import VARIANT; variant = VARIANT(3)", + "variant.value # comtypes") + timeit('-s', "from comtypes.automation import VARIANT; variant = VARIANT()", + "variant.value = 3.14 # comtypes") ! # on my machine: ! ##ctypes version: 0.9.2 ! ##python version: 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] ! ## 0.38: Class() ! ## 1.97: POINT() ! ## 1.98: RECT() ! ## 0.24: point.y ! ## 2.43: rect.lr ! ## 7.21: fd.lprgelemdescParam ! ## 10.90: fd.lprgelemdescParam[0] ! ## 12.00: fd.lprgelemdescParam[1] ! ## 15.30: fd.lprgelemdescParam[1].tdesc ! ## 16.00: fd.lprgelemdescParam[1].tdesc.vt ! ## 26.20: fd.lprgelemdescParam[1].tdesc.u.lptdesc[0].vt ! ## 1.80: c_int() ! ## 1.97: c_int(42) ! ## 2.93: VARIANT() # ctypes.com ! ## 5.30: variant.value # ctypes.com ! ## 11.60: variant.value = 3.14 # ctypes.com + ##ctypes version: 0.9.3 + ##python version: 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] + ## 0.41: Class() + ## 1.34: POINT() + ## 1.39: RECT() + ## 0.23: point.y + ## 2.36: rect.lr + ## 7.22: fd.lprgelemdescParam + ## 10.80: fd.lprgelemdescParam[0] + ## 10.90: fd.lprgelemdescParam[1] + ## 13.50: fd.lprgelemdescParam[1].tdesc + ## 14.40: fd.lprgelemdescParam[1].tdesc.vt + ## 21.70: fd.lprgelemdescParam[1].tdesc.u.lptdesc[0].vt + ## 1.13: c_int() + ## 1.32: c_int(42) + ## 2.34: VARIANT() # ctypes.com + ## 5.49: variant.value # ctypes.com + ## 11.60: variant.value = 3.14 # ctypes.com + ## 1.40: VARIANT() # comtypes + ## 5.54: variant.value # comtypes + ## 12.10: variant.value = 3.14 # comtypes |