[IPython-dev] Feature request/how?

Charles Moad cmoad at indiana.edu
Tue Feb 22 09:29:31 EST 2005

	First of all, thanks for the code.  I am getting unexpected results 
however.  For example, "%time time.sleep(5)" shows "Call time: 0.00 s." 
  I also have xmlrpc calls that take about 60 seconds that show a call 
time of about 0.04 s.  Are we thinking of different things?
	Is it not possible to include assignment operators as well?  Only 
simple expressions seem to work.

Thanks again,

Fernando.Perez at colorado.edu wrote:
> Quoting Charles Moad <cmoad at indiana.edu>:
>>	Thanks for the pointer.  I am still fuzzy on how I would create a magic
>>function using this, since I need to run the parameter_s arg of the
>>magic function in the current context.  timing/timings takes the
>>actually function and args, not a string.
> It was quicker to just write the code rather than to explain how to do it.  Here
> it is, it will go into the .12 release.  I still need to write a docstring for
> it (that always takes longer than the actual code).
> Best,
> f
>     def magic_time(self,parameter_s = ''):
>         """Time execution of an expression which can be passed to eval().
>         The value of the expression is returned."""
>         # fail immediately if the given expression can't be compiled
>         code = compile(parameter_s,'<timed evaluation>','eval')
>         # skew measurement as little as possible
>         glob = self.shell.user_ns
>         clk = clock
>         # time execution
>         s = clk()
>         out = eval(code,glob)
>         tot = clk()-s
>         print "Call time: %.2f s." % tot
>         return out

More information about the IPython-dev mailing list