On Wed, 02 Nov 2011 10:34:27 +0100 Marcel Gädigk email@example.com wrote:
i using the Perspective Broker and i have problems with the speed of importing the modules. It takes 15 - 17 seconds for importing the Reactor and the PBServerFactory (or other pb imports). If i import the reactor or the pb imports alone it takes in avg. 2-3 seconds.
def ImportIt(): from twisted.internet import reactor from twisted.spread.pb import PBServerFactory
import timeit t = timeit.Timer(setup='from __main__ import ImportIt', stmt='ImportIt()') print t.timeit()
Er, have read the timeit docs? The timeit() method will execute the given code *one million times* by default:
timeit(self, number=1000000) unbound timeit.Timer method Time 'number' executions of the main statement.
To be precise, this executes the setup statement once, and then returns the time it takes to execute the main statement a number of times, as a float measured in seconds. The argument is the number of times through the loop, defaulting to one million. The main statement, the setup statement and the timer function to be used are passed to the constructor.
You might want to rewrite your script without timeit and simply use the "time" command. Or call `t.timeit(1)` instead.