0 Members and 1 Guest are viewing this topic.
(BenchMark '((Str-Make-CAB '("1" "2" "3" "4") "+") (Str-Make-Lee '("1" "2" "3" "4") "+")))Benchmarking ................Elapsed milliseconds / relative speed for 8192 iteration(s): (STR-MAKE-LEE (QUOTE ("1" "2" "3" "4...).....1763 / 1.01 <fastest> (STR-MAKE-CAB (QUOTE ("1" "2" "3" "4...).....1778 / 1.00 <slowest>_$ (BenchMark '((Str-Make-CAB '("1" "2" "3" "4") "+") (Str-Make-Lee '("1" "2" "3" "4") "+")))Benchmarking ................Elapsed milliseconds / relative speed for 8192 iteration(s): (STR-MAKE-LEE (QUOTE ("1" "2" "3" "4...).....1763 / 1.03 <fastest> (STR-MAKE-CAB (QUOTE ("1" "2" "3" "4...).....1810 / 1.00 <slowest>
(Str-Make-CAB '("1" "2" "3" "4") '(30 10 30 0) "+")
(defun Str-Make (lst del / Pad str) (defun Pad (pStr pDel Len) (or (zerop len) (while (>= (strlen pStr) len) (setq len (+ len 10))) (while (< (strlen pStr) Len) (setq pStr (strcat pStr pDel))) ) pStr ) (setq str "") (mapcar (function (lambda(str$ len#) (setq str (strcat Str (Pad str$ del len#))))) lst '(30 10 30 0)) str)
(BenchMark '((Str-Make-Lee '("1" "2" "3" "4") "+") (Str-Make-CAB1 '("1" "2" "3" "4") "+") (Str-Make-CAB2 '("1" "2" "3" "4") "+")))Benchmarking ................Elapsed milliseconds / relative speed for 8192 iteration(s): (STR-MAKE-CAB2 (QUOTE ("1" "2" "3" "...).....1810 / 1.01 <fastest> (STR-MAKE-LEE (QUOTE ("1" "2" "3" "4...).....1825 / 1.00 (STR-MAKE-CAB1 (QUOTE ("1" "2" "3" "...).....1825 / 1.00 <slowest>_$ (BenchMark '((Str-Make-Lee '("1" "2" "3" "4") "+") (Str-Make-CAB1 '("1" "2" "3" "4") "+") (Str-Make-CAB2 '("1" "2" "3" "4") "+")))Benchmarking ................Elapsed milliseconds / relative speed for 8192 iteration(s): (STR-MAKE-LEE (QUOTE ("1" "2" "3" "4...).....1779 / 1.03 <fastest> (STR-MAKE-CAB1 (QUOTE ("1" "2" "3" "...).....1794 / 1.02 (STR-MAKE-CAB2 (QUOTE ("1" "2" "3" "...).....1825 / 1.00 <slowest>_$ (BenchMark '((Str-Make-Lee '("1" "2" "3" "4") "+") (Str-Make-CAB1 '("1" "2" "3" "4") "+") (Str-Make-CAB2 '("1" "2" "3" "4") "+")))Benchmarking ................Elapsed milliseconds / relative speed for 8192 iteration(s): (STR-MAKE-LEE (QUOTE ("1" "2" "3" "4...).....1794 / 1.03 <fastest> (STR-MAKE-CAB2 (QUOTE ("1" "2" "3" "...).....1826 / 1.01 (STR-MAKE-CAB1 (QUOTE ("1" "2" "3" "...).....1841 / 1.00 <slowest>
(defun Pad-VovKa (String Char NewLen / PadString) (if (> (setq NewLen (- NewLen (strlen String))) 0) (strcat String (progn (setq PadString (if (zerop (rem NewLen 2)) "" Char ) Char (strcat Char Char) ) (repeat (/ NewLen 2) (setq PadString (strcat PadString Char))) PadString ) ) String ))
BTW Lee that is clever method to get the 30 10 30.
this will speed up things a bit
(defun Str-Make-ee (lst del len) (repeat 6 (setq del (strcat del del))) (apply (function strcat) (mapcar (function (lambda (a b / s) (if (< (setq s (strlen a)) b) (strcat a (substr del 1 (- b s))) a ) ;_ if ) ;_ lambda ) ;_ function lst len ) ;_ mapcar ) ;_ apply)
(setq lst '("1" "2" "3" "4") del "+" len '(30 10 30 0))(BenchMark '((Str-Make-CAB2 lst del) (Str-Make-CAB1 lst del) (Str-Make-Lee lst del) (Str-Make-ee lst del len) )) ;_ BenchMarkBenchmarking .................Elapsed milliseconds / relative speed for 16384 iteration(s): (STR-MAKE-EE LST DEL LEN).....1953 / 2.66 <fastest> (STR-MAKE-CAB2 LST DEL).......5047 / 1.03 (STR-MAKE-CAB1 LST DEL).......5047 / 1.03 (STR-MAKE-LEE LST DEL)........5203 / 1 <slowest>
(repeat (1+ (fix (/ (log (apply 'max Len)) (log 2)))) (setq del (strcat del del)) )
Nice variant Evgeniy! I wouldn't have immediately thought to create the "Padding string" first.. of course it would only work for padding < 2^6 in length, but I'm sure that's sufficient Lee