redirecting newLISP functions and timing them

Started by cormullion, May 05, 2007, 10:02:39 AM

Previous topic - Next topic

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">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:


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

nigelbrown

#1
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

cormullion

#2
cool idea!