Profiling your application

Notices and updates
Locked
Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Profiling your application

Post by 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

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:

Code: Select all

> (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...

Artful code

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

It's added (but not thoroughly tested)
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

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...

Artful code

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

invalid 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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

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...

Artful code

Locked