Author Topic: Quick ODBX Question  (Read 10340 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Quick ODBX Question
« Reply #15 on: January 15, 2010, 07:01:57 PM »
Nice one CAB - thats good, but of course it would only apply to lists of length 4  :-)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Quick ODBX Question
« Reply #16 on: January 15, 2010, 07:19:01 PM »
Unexpectedly:

Code: [Select]
(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>

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Quick ODBX Question
« Reply #17 on: January 15, 2010, 07:56:03 PM »
Yes, unexpected.
As for the number of string items, to make it universal i would think you would also pass the length list with it.
Code: [Select]
(Str-Make-CAB '("1" "2" "3" "4") '(30 10 30 0) "+")
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Quick ODBX Question
« Reply #18 on: January 15, 2010, 07:58:35 PM »
How does this version time out?
Code: [Select]
(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
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Quick ODBX Question
« Reply #19 on: January 15, 2010, 08:02:39 PM »
Not too much in it:

Code: [Select]
(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>

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Quick ODBX Question
« Reply #20 on: January 15, 2010, 08:19:29 PM »
How many milliseconds does it take to blink? 8-)


I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Quick ODBX Question
« Reply #21 on: January 15, 2010, 08:23:53 PM »
In any case, I have updated the code in my previous post  :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Quick ODBX Question
« Reply #22 on: January 15, 2010, 10:55:04 PM »
BTW Lee that is clever method to get the 30 10 30.  8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Quick ODBX Question
« Reply #23 on: January 16, 2010, 04:58:28 AM »
this will speed up things a bit
Code: [Select]
(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
  )
)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Quick ODBX Question
« Reply #24 on: January 16, 2010, 08:03:18 PM »
BTW Lee that is clever method to get the 30 10 30.  8-)

Thanks Alan  8-)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Quick ODBX Question
« Reply #25 on: January 16, 2010, 08:12:18 PM »
this will speed up things a bit

Nice idea VovKa!  Halving the amount of operations  :-D

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Quick ODBX Question
« Reply #26 on: January 17, 2010, 02:48:35 AM »
My variant:

Code: [Select]
(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
)
test:
Code: [Select]
(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)
            )
) ;_  BenchMark
Benchmarking .................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>


Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Quick ODBX Question
« Reply #27 on: January 17, 2010, 07:52:45 AM »
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

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Quick ODBX Question
« Reply #28 on: January 17, 2010, 07:55:43 AM »
i think this should be sufficient :)
Code: [Select]
(repeat (1+ (fix (/ (log (apply 'max Len)) (log 2))))
    (setq del (strcat del del))
  )

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Quick ODBX Question
« Reply #29 on: January 17, 2010, 07:59:46 AM »
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

Hi Lee, if you know in advance a symbol for addition easier not to create and write down it in the program:
"++++++++++++++++++++++++++++++++++++++++"