[python-win32] Dispatch vs EnsureDispatch performance
Sven Bardos
sven.bardos at googlemail.com
Wed Apr 17 02:07:24 EDT 2024
Hi,
shouldn't be EnsureDispatch be faster than Dispatch once the code
generation is done?
I've measured it by calling 6000 COM calls like this:
dirpath = Path('C:/Users/sbardos/AppData/Local/Temp/gen_py/3.10/')
if dirpath.exists() and dirpath.is_dir():
shutil.rmtree(dirpath)
app = Dispatch("CT.Application")
job = app.CreateJobObject()
start = timer()
for i in range(2000):
cnt, devIds = job.GetAllDeviceIds()
cnt, sheetIds = job.GetSheetIds()
dev = job.CreateDeviceObject()
end = timer()
print(f"Time ellapsed (late): {end - start}s")
and the ensure Dispatch version:
app = EnsureDispatch("CT.Application")
job = app.CreateJobObject()
start = timer()
for i in range(2000):
cnt, devIds = job.GetAllDeviceIds(None)
cnt, sheetIds = job.GetSheetIds(None)
dev = job.CreateDeviceObject()
end = timer()
print(f"Time ellapsed (early): {end - start}s")
EnsureDispatch is a little bit slower ~4.2s compared to ~4.0s.
If I don't get a performance boost with EnsureDispatch, is there even a
point using it?
Thanks,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/python-win32/attachments/20240417/1b4f6707/attachment-0001.html>
More information about the python-win32
mailing list