So after much research on the library .  It certainly looks like the invoke
method is taking all the time.  Is this because of the conversion from
Variant???

On Tue, Feb 7, 2017 at 11:09 AM, Stephen Chapman <schapman1...@gmail.com>
wrote:

> Hello,
>    I am having a speed issue while running dll functions.  I have a
> minimal com server example and a minimal com client example below.  I have
> added cProfile to the example.  All source files and the profile are
> attached.
>
>    So when I run this example I get between 1.4 seconds to 1.7 seconds.  I
> am running a loop of 10,000 doing 2 methods in the loop.  So the here are a
> couple lines from the profile.
>
>    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
>         1    0.050    0.050    1.740    1.740 cpminimaltest.py:6(
> testcalltime)
>     20001    0.103    0.000    1.689    0.000 dynamic.py:41(__call__)
>     20004    0.698    0.000    1.247    0.000 automation.py:702(Invoke)
>     80001    0.276    0.000    0.313    0.000 automation.py:197(_set_value)
>
> It seems like the Invoke is taking an inordinate amount of time.  When I
> create a minimal example in C# and run the same test.  I get .009
> seconds.   Is there something I am not doing right.  Would having a tlb
> file attached help?...
>
>
> <minimal server example>
> from win32com.server import register
> import sys
> import pstats
> import cProfile
>
> class dataObject(object):
>     _public_methods_  = ["method1","method2","startProfile","printStats"]
>     _public_attrs_    = []
>     _reg_progid_      = "testcall.dataobject"
>     _reg_desc_        = "simple test project"
>     _reg_clsid_       = "{97dbc38f-44ce-11e2-a5e5-001018107395}"
>
>     def __init__(self):
>         self.profile = cProfile.Profile()
>
>     def method1(self,*args):
>         return 0
>
>     def method2(self,*args):
>         return 0
>
>     def startProfile(self):
>         self.profile.enable()
>
>     def printStats(self,filename=""):
>         self.profile.disable()
>         f = open(filename, 'w')
>         sortby = 'cumulative'
>         try:
>             pstats.Stats(self.profile, stream=f).strip_dirs().sort_
> stats(sortby).print_stats()
>         except:
>             f.write("Nothing was profiled\n")
>         f.close()
>
> if __name__=='__main__':
>     if len(sys.argv)>1:
>         register.UnregisterServer(dataObject)
>     else:
>         register.UseCommandLine(dataObject)
>
>
> <minimal client example>
> from comtypes.client import CreateObject
> import time
>
> do = CreateObject("testcall.dataobject")
>
> def testcalltime():
>     c4 = 0
>     a=time.time()
>     for d in range (0,10000):
>         d=do.method1(c4,1)
>         e=do.method2(c4,1)
>     b=time.time()
>     print b-a
>
> do.startProfile()
> testcalltime()
> do.printStats("c:\profile.txt")
>
>
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to