Simple profiling tool¶
AUTHORS:
 David Harvey (August 2006)
 Martin Albrecht

class
sage.misc.profiler.
Profiler
(systems=[], verbose=False)¶ Bases:
object
Keeps track of CPU time used between a series of userdefined checkpoints.
It’s probably not a good idea to use this class in an inner loop :)
EXAMPLES:
sage: def f(): # not tested ....: p = Profiler() # not tested
Calling
p(message)
creates a checkpoint:sage: p("try factoring 15") # not tested
Do something timeconsuming:
sage: x = factor(15) # not tested
You can create a checkpoints without a string;
Profiler
will use the source code instead:sage: p() # not tested sage: y = factor(25) # not tested sage: p("last step") # not tested sage: z = factor(35) # not tested sage: p() # not tested
This will give a nice list of timings between checkpoints:
sage: print(p) # not tested
Let’s try it out:
sage: f() # not tested 3.020s  try factoring 15 15.240s  line 17: y = factor(25) 5000.190s  last step
See also
Todo
 Add Pyrex source code inspection (I assume it doesn’t currently do this)
 Add ability to sort output by time
 Add option to constructor to print timing immediately when checkpoint is reached
 Migrate to Pyrex?
 Add ability to return timings in a more machinefriendly format
AUTHOR:
 David Harvey (August 2006)

clear
()¶

print_last
()¶ Prints the last profiler step