4

I'm writing a web application (http://www.checkio.org/) which allows users to write python code. As one feedback metric among many, I'd like to enable profiling while running checks on this code. This is to allow users to get a very rough idea of the relative efficiency of various solutions.

I need the profile to be (reasonably) deterministic. I don't want other load on the web server to give a bad efficiency reading. Also, I'm worried that some profilers won't give a good measurement because these short scripts run so quickly. The timeit module shows a function being run thousands of time, but I'd like to not waste server reasources on this small features if possible.

It's not clear which (if any) of the standard profilers meet this need. Ideally the profiler would give units of "interpreter bytecode ticks" which would increment one per bytecode instruction. This would be a very rough measure, but meets the requirements of determinism and high-precision.

Which profiling system should I use?

bukzor
  • 37,539
  • 11
  • 77
  • 111
  • Not everything is run as interpreter bytecode, so this is a poor measure of time. One "interpreter bytecode tick" in which native code is called could take microseconds or hours. – detly May 02 '11 at 01:12
  • If you want people to be able to find their bottlenecks, [allow them to take stack samples](http://stackoverflow.com/questions/4295799/how-to-improve-performance-of-this-code/4299378#4299378). – Mike Dunlavey May 02 '11 at 02:12
  • @detly: I know that it's a poor measure, but in this particular environment, where most C extensions are disallowed by the sandbox, it should be good enough to let people say "oh, my solution is slower than that one" or even "I've just improved by 30x!". The real question is, where do I find this poor profiler? – bukzor May 02 '11 at 03:27

2 Answers2

1

Python's standard profiler module provides deterministic profiling.

vartec
  • 131,205
  • 36
  • 218
  • 244
  • But that doesn't mean the profile results will be deterministic. You're confusing yourself with the terminology. – bukzor May 02 '11 at 03:25
  • 1
    bukzor: and how will that be non-deterministic? profilers take in account CPU time, not real time. So load does not affect the result. – vartec May 02 '11 at 16:30
0

I also suggest giving a try to yappi. (http://code.google.com/p/yappi/) In v0.62, it supports CPU time profiling and you can stop the profiler at any time you want...

Sumer Cip
  • 179
  • 2
  • 11