Page 1 of 1

redirecting newLISP functions and timing them

Posted: Sat May 05, 2007 5:02 pm
by cormullion
Thinking about a recent suggestion that it might be possible to add timing details to functions... I've learned that you can redirect newLISP functions:

http://www.alh.net/newlisp/phpbb/viewtopic.php?p=7985

So it should be easy to write a function or macro that does it for a set of functions... However, I quickly got stuck in a morass and only found a way out using a machete:

Code: Select all

(dolist (_smbl '(sin cos tan))
  (set '_f (name _smbl))
  (eval-string (format {(constant (global (sym (string "newLISP-" "%s"))) %s)} _f _f)) ; safe copy
  (eval-string (format {
   (define (my-%s:my-%s) 
   (let
    ((_t (time-of-day))
    (_d (date (date-value) 0 "%%Y-%%m-%%d %%H:%%M:%%S")))
   (apply (string "my-" %s) (args))
   (append-file "/Users/me/desktop/log" (string _d " " (quote %s) " " (sub (time-of-day) _t) "\n")))) ; timing info
  } _f _f _f _f))    
  (set '_s (format {(constant (global (quote %s)) my-%s)} _f _f))
  (eval-string _s)) ; redirect
This sends execution times of trig functions to a log file. But there has to be a better way!

Interesting question: is it be possible to do this for all built-in newLISP functions?

Posted: Sat May 05, 2007 9:14 pm
by nigelbrown
Perhaps a new system function (profile [exp]) which is like trace but
1) traces all functions or maybe just user functions
2) doesn't pause for "s|tep n|ext c|ont q|uit >" but just writes trace info with system time attached and then automatically does step
3) with [exp] serving the same purpose as in trace

or maybe just give trace this behavior as an option?

Thoughts Lutz?

Regards
Nigel

Posted: Sat May 05, 2007 9:50 pm
by cormullion
cool idea!