>> If you want to post some specific code examples, I'm
>> happy to talk you through possible optimisations.
>>
>> TJG
> 
> Sorry I didn't reply right away. Here's the straight WMI code I'm
> using:
> 
> c = wmi.WMI()
>     for i in c.Win32_ComputerSystem():
>         mem = int(i.TotalPhysicalMemory)
>         compname = i.Name
> for i in c.Win32_Processor ():
>         cputype = i.Name

Well, don't know how much gain you'll get, but yo
could try the following quickies:

<code>
import wmi
c = wmi.WMI (find_classes=False)

for i in c.Win32_ComputerSystem (
   ['TotalPhysicalMemory', 'Name']
):
   mem = int (i.TotalPhysicalMemory)
   compnam = i.Name

for i in c.Win32_Processor (['Name']):
   cputype = i.Name

</code>

If you were going to repeat these often (say, in
a loop, which doesn't seem likely given you
examples) you might gain a few nanosecs by
pulling the attribute lookup outside the loop:

<code>
import wmi
c = wmi.WMI (find_classes=False)

ComputerSystem = c.Win32_ComputerSystem
Processor = c.Win32_Processor

while True:
   for computer_system in ComputerSystem (...): ...
   for processor in Processor (...): ...

</code>

But, as everyone else on this list will tell you,
there's no point in optimising unless you know you
need to to, and unless you know where :-) That's
what modules like timeit profiler are for.

TJG
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to