;;;------------------------------------------------------------------
;;;
(defun benchmark
;;================================================================= ;;
;; Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
;;
;; Mods by KWB 2005 Ordered with fastest as relative speed 1.00
;;=================================================================
;;
;; Purpose:
;;
;; Compare the performance of various statements.
;;
;; Notes:
;;
;; I make no claims that this is definitive benchmarking. I
;; wrote this utility for my own purposes and thought I'd
;; share it. Many considerations go into evaluating the
;; performance or suitability of an algorythm for a given
;; task. Raw performance as profiled herein is just one.
;;
;; Please note that background dramatically affect results.
;;
;; Disclaimer:
;;
;; This program is flawed in one or more ways and is not fit
;; for any particular purpose, stated or implied. Use at your
;; own risk.
;;
;;=================================================================
;;
;; Syntax:
;;
;; (Benchmark statements)
;;
;; Where statements is a quoted list of statements.
;;
;;=================================================================
;;
;; Example:
;;
;; (BenchMark
;; '(
;; (1+ 1)
;; (+ 1 1)
;; (+ 1 1.0)
;; (+ 1.0 1.0)
;; )
;; )
;;
;;=================================================================
;;
;; Output:
;;
;; Elapsed milliseconds / relative speed for 32768 iteration(s):
;;
;; (+ 1 1.0).......1452 / 1.1152 <slowest>
;; (+ 1.0 1.0).....1412 / 1.0845
;; (+ 1 1).........1332 / 1.023
;; (1+ 1)..........1302 / 1 <fastest>
;;
;; Mods by KWB 2005
;;
;;=================================================================
(statements / _lset _rset _tostring _eval _princ _main)
;;=================================================================
;;
;; (_LSet text len fillChar)
;;
;;=================================================================
(defun _lset
(text len fillchar
/ padding result
) result
(vl
-string
->list text
) )
(substr (vl
-list
->string result
) 1 len
) )
;;=================================================================
;;
;; (_RSet text len fillChar)
;;
;;=================================================================
(defun _rset
(text len fillchar
/ padding result
) result
(vl
-string
->list text
) )
)
;;=================================================================
;;
;; (_ToString x)
;;
;;=================================================================
(defun _tostring
(x
/ result
) result
)
)
;;=================================================================
;;
;; (_Eval statement iterations)
;;
;;=================================================================
(defun _eval
(statement iterations
/ start
) (- (getvar "millisecs") start
) )
;;=================================================================
;;
;; (_Princ x)
;;
;;=================================================================
;; forces screen update
)
;;=================================================================
;;
;; (_Main statements)
;;
;;=================================================================
(defun _main
(statements
/ boundary iterations
timings slowest
fastest lsetlen
rsetlen index
count
)
(setq boundary
200 ; 1000 iterations 1
)
(_princ "Benchmarking [M.P. 2005 < revised kdub 2005>] ...")
statements
)
)
)
boundary
)
)
(setq iterations
(* 2 iterations
)) (_princ ".")
)
(_princ
(strcat "\nElapsed milliseconds for " " iteration(s)"
"/ relative Timing :\n\n"
)
)
)
(+ 5
)
)
)
)
)
)
)
(_lset
(car pair
) lsetlen
".") " / "
(rtos (/ ms fastest
) 2 4) ((eq index count
) " <fastest>") ("")
)
"\n"
)
)
)
pair
)
)
)
;;=================================================================
;;
;; Program is defined, let's rock and roll ...
;;
;;=================================================================
(_main statements)
)