Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: help with function utilising "extended life-time" words ..

From: ingo:2b1 at: 1-Oct-2003 19:09

Hi Pekr, Petr Krenzelok wrote:
> Hello,
<...>
> start: now/time/precise .... do something ... print now/time/precise - > start start: now/time/precise > > I wanted to write myself short logger function, which will save me from > repeating above sequences, as the script becomes a bit messy then. So I > wanted to have following interface:
<...> Maybe this script will help a little, I normally use only profiler/test [a short snip I want to test] 10000 but it "should" be possible to set different profiler marks in your script, and test them later, but that's not tested. I hope that helps, Ingo -- Attached file included as plaintext by Ecartis -- -- File: profiler.r REBOL [ Title: "Rebol Profiler" Author: "Ingo Hohmann" ] profiler: context [ markers: [] mark: func [ "adds a profiler mark" marker [word!] ] [ insert tail markers reduce [ marker now/time/precise ] ] show: func [ "shows time since setting a profiler mark" marker [word!] /local t walk ret-val last-val tmp-val ] [ ret: copy [] t: now/time/precise if walk: find markers marker [ walk: next walk last-val: first walk while [walk: find walk marker] [ walk: next walk append ret (first walk) - last-val last-val: first walk ] ] ret ] test: func [ {tests a block for speed *!* clears the markers block *!*} block [block!] times [integer!] ] [ block: copy/deep block clear mark 't loop times [do block] mark 't show 't ] clear: func [ "Clears all markers" /only marker [word!] /local walk ] [ either only [ walk: find markers marker until [ remove/part walk 2 not found? find walk marker ] ] [ system/words/clear markers ] ] next-marker: 1 _func: function! ; ; ToDo: ; create a list of marks, find a way to name the functions ; profiling-func: func [ {Adds profiling data to a normal function} [catch] spec [block!] {Help string (opt) followed by arg words (and opt type and string)} body [block!] "The body block of the function" /local pre post ][ pre: copy [catch/name ] post: copy ['profiling-return] insert body compose [profiler/mark (to-word join 'm next-marker)] next-marker: next-marker + 1 insert tail insert/only tail pre body post probe pre ] install: func [ {Installs a profiling 'func every new func after this will create a profiling function} ][ _func: :func func: :profiling-func ] ]