Profiling your application

Started by Jeff, July 28, 2008, 09:33:07 AM

Previous topic - Next topic

Jeff

I wrote a simple profiler that gives you the number of calls to a function and how long was spent in the function:



http://static.artfulcode.net/newlisp/profiler.lsp.html">http://static.artfulcode.net/newlisp/profiler.lsp.html



The overhead is pretty low - a call to time and two calls to inc per profiled function call.  Even with the overhead, though, the relative stats are useful, and the larger the function, the less relative the overhead per call is.  In that way, it is somewhat skewed on small function calls, but only by ~5 ms for each 10,000 calls:


> (setq x 0 y 0)
0
> (time (begin (inc 'x) (inc 'y (time '()))))
0
> (time (begin (inc 'x) (inc 'y (time '()))) 10)
0
> (time (begin (inc 'x) (inc 'y (time '()))) 100)
0
> (time (begin (inc 'x) (inc 'y (time '()))) 1000)
0
> (time (begin (inc 'x) (inc 'y (time '()))) 10000)
5
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

cormullion

#1
Works really well Jeff! I like the output - very neat. (I'd quite like a %age of total time column as well! :)

Jeff

#2
It's added (but not thoroughly tested)
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

cormullion

#3
Jeff - I've been trying to get this running on newlisp 9.3 without success - is it using 9.4-specific features?

Jeff

#4
I don't remember.  It uses the new dictionary syntax, I know that.  What is the error you are getting?
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

cormullion

#5
Quoteinvalid function : (calls "markdown:amps-and-angles" 0)

called from user defined function Profiler:profile-functions

called from user defined function Profiler:profile-context


I think it must be the new hash table stuff in 9.4?



I thought I'd try and get some profiling done of the blog output, but there I'm stuck on 9.3.



No problem...

Lutz

#6
You can easily replace a hash with context statements, to make it work on older versions of newLISP:



(MyHash <str-key> <value>)

replace with  

(context MyHash <str-key> <value>)



(MyHash <str-key>)  

replace with

(context MyHash <str-key>)



Leave the (define MyHash:MyHash) statement, because it conveniently creates and pre-declares the context, wihtout the need to switch back to MAIN when using the alternative: (context 'MyHash) (context MAIN).



The only difference between the two methods is, that when using the 'context' function,  there is no underscore prepended to the key. But this shouldn't make a difference in most applications. Else both methods are completely compatible and do the same things internally.

Jeff

#7
I think the profiler uses the underscores in situations when it needs to iterate over the keys.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code