1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2% 3% File: QUALIFIED-TIMING.SL 4% Description: timing function execution 5% Author: Herbert Melenk and Winfried Neun, ZIB Berlin 6% Created: 25 October 1988 7% Mode: Lisp 8% Package: Utilities 9% Status: Open Source: BSD License 10% 11%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 12% 13% Redistribution and use in source and binary forms, with or without 14% modification, are permitted provided that the following conditions are met: 15% 16% * Redistributions of source code must retain the relevant copyright 17% notice, this list of conditions and the following disclaimer. 18% * Redistributions in binary form must reproduce the above copyright 19% notice, this list of conditions and the following disclaimer in the 20% documentation and/or other materials provided with the distribution. 21% 22% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24% THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25% PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNERS OR 26% CONTRIBUTORS 27% BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33% POSSIBILITY OF SUCH DAMAGE. 34% 35%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 36 37(compiletime (flag '(qualtime1 qualtime11 print-qualtime1) 38 'internalfunction)) 39 40(cond ((not (getd 'priv-time-get)) (copyd 'priv-time-get 'get))) 41(cond ((not (getd 'priv-time-put)) (copyd 'priv-time-put 'put))) 42 43(imports '(compiler)) 44 45(fluid '(*allqualtime* *allqualtimetime*)) 46 47%%(on comp) 48 49(dm qualtime (u) 50 (mapc (cdr u) (function qualtime1)) 51 NIL) 52 53(de qualtime1 (u) 54 (eval (qualtime11 u)) 55 (setq *allqualtimetime* (cons (timc) gctime*)) 56 NIL) 57 58(de qualtime11(u) 59 (let ((name (intern (gensym)))(name2 (intern (gensym)))) 60 (push u *allqualtime*) 61 (unless (getd u) (return nil)) 62 (when (eq u 'equal) (prin2t " Timing for Equal impoosible") 63 (return NIL)) 64 (fluid1 name) 65 `(progn 66 (copyd ',name ',u) 67 (setq ,name t) 68 (de ,name2 (x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 ) 69 (prog (returnvalue time1 countpos nam) 70 (setq nam ,name) 71 (cond( nam (setq time1 (timc)))) 72 (setq ,name NIL) 73 74 (setq returnvalue 75 (,name x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 )) 76 77 (cond ((not nam) (return returnvalue))) 78 (setq ,name T) 79 (setq time1 (wdifference (timc) time1)) 80 (setq countpos (priv-time-get ',u 'qualtimetime)) 81 (cond (countpos 82 (priv-time-put ',u 'qualtimetime (wplus2 countpos time1))) 83 (t (priv-time-put ',u 'qualtimetime time1))) 84 (setq countpos (priv-time-get ',u 'qualtime)) 85 (cond (countpos 86 (priv-time-put ',u 'qualtime (wplus2 1 countpos))) 87 (t (priv-time-put ',u 'qualtime 1))) 88 (return returnvalue) 89 ) ) 90 (compile (list ',name2)) 91 (copyd ',u ',name2) 92) ) ) 93 94(de print-qualtime () 95 (prog (uu uuu) 96 (setq uu (wdifference (timc) (car *allqualtimetime*))) 97 (setq uuu (wdifference gctime* (cdr *allqualtimetime*))) 98 (setq *allqualtimetime* (wdifference uu uuu)) 99 (prin2t " *********** Qualified Timing **************") 100 (prin2l (list " **** Overall Cpu time : " 101 *allqualtimetime* " *****")) 102 (terpri) 103 (terpri) 104 (mapc *allqualtime* (function print-qualtime1)) 105 (reset-qualtime))) 106 107(de print-qualtime1 (u) 108 (prog (x) 109 (prin2 " *** ") 110 (prin2 u) (tab 30) 111 (prin2 " * calls : ") 112 (prin2 (priv-time-get u 'qualtime)) 113 (when (not (priv-time-get u 'qualtime)) (terpri) (return nil)) 114 (tab 45) 115 (prin2 " * time : ") 116 (prin2 (priv-time-get u 'qualtimetime)) 117 (tab 60) 118 (prin2 " * % ") 119 (prin2t (quotient (times2 100 (priv-time-get u 'qualtimetime)) 120 (wplus2 1 *allqualtimetime*))) 121) ) 122 123(de reset-qualtime() (mapobl (function (lambda (x) 124 (remprop x 'qualtimetime) 125 (remprop x 'qualtime)))) 126 (setq *allqualtimetime* (cons (timc) gctime*))) 127 128(prin2t "use (qualtime function function ... ), (print-qualtime)") 129