Author Topic: ( Challenge ) Just curious  (Read 8702 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: ( Challenge ) Just curious
« Reply #15 on: December 01, 2006, 05:17:53 PM »
Holy Katz, Tim! Is my laptop really that slow?. <grumble.wav>
Intel(R)Xeo (processor?)
2.8GHz
1Gb Ram
I have Lotus Notes, Outlook 6, Firefox, Exploer,  Winamp (ssshh!! don't tell my boss) AutoCAD Electrial '06 running at the time tested.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ( Challenge ) Just curious
« Reply #16 on: December 01, 2006, 07:04:47 PM »
Jeff,  Alan ,

I've noticed that some of the others are opening the file before they start the timer .... that may shave a little bit off if you are concerned about time.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Jeff_M

  • King Gator
  • Posts: 3944
  • C3D user & customizer
Re: ( Challenge ) Just curious
« Reply #17 on: December 01, 2006, 07:20:18 PM »
Thanks for the thought, Kerry. Although it doesn't save all that much...:

Code: [Select]
(progn
  (setq timer (getvar "millisecs"))
  (setq file1 (open "C:\\Base Maps\\Jeffs Test Files\\junk\\numbers.csv" "R"))
  (close file1)
  (princ (strcat "Process took " (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2) " seconds."))
  )
Process took 0.03 seconds.

Of course I guess this just proves that Lisp was not designed to work, at least not quickly, with large data sets.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: ( Challenge ) Just curious
« Reply #18 on: December 01, 2006, 07:57:59 PM »
Still, 2.5 seconds is not too slouchfull for an interpreted language ..

read 10,000 line of text with 10 values each line
translate text in each line to numbers
evaluate min
evaluate max
write values to file

rinse and repeat ....

.... there's a lot going on there ....

Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Andrea

  • Water Moccasin
  • Posts: 2360
Re: ( Challenge ) Just curious
« Reply #19 on: December 01, 2006, 08:31:28 PM »
there is mine...

Code: [Select]
(defun c:minmax (/ start-time f1 l1 lineM #low #hi newfile end-time fr)
(setq f1 (open (getfiled "Please select your file..." "" "csv" 8) "r")
      l1 (read-line f1))
(setq start-time (getvar "cdate"))
(if l1 (setq newfile (open "c:\\result.txt" "w")))
(while l1
(setq lineM (read (strcat "(" (acet-str-replace "," " "  l1) ")"))
       #low (car (vl-sort lineM '<))
        #hi (car (vl-sort lineM '>)))
(write-line (strcat (rtos #hi) " " (rtos #low)) newfile)

(setq l1 (read-line f1)))

(close f1)
(close newfile)

(setq end-time (getvar "cdate")
fr (substr (rtos (- end-time start-time) 2 10) 7))
(alert (strcat "Done in only ..." (substr fr 1 2) "," (substr fr 3) " sec."))
)
Keep smile...

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1540
  • Moscow (Russia)
Re: ( Challenge ) Just curious
« Reply #20 on: December 02, 2006, 04:46:42 AM »
Process took 0.03 seconds.
:-o

for my pc...
Code: [Select]
(progn
  ;;Jeff_M
  (setq timer (getvar "millisecs"))
  (repeat 100
  (setq
    file1 (open "D:\\numbers.csv"
                "R"
          ) ;_ open
  ) ;_ setq
  (close file1)
    )
  (princ
    (strcat "Process took "
            (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 4)
            " seconds."
    ) ;_ strcat
  ) ;_ princ
  (princ)
)

repeat 100:
Process took 0.015 seconds.
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1540
  • Moscow (Russia)
Re: ( Challenge ) Just curious
« Reply #21 on: December 02, 2006, 06:20:45 AM »

Code: [Select]
(defun c:test_1 (/ f timer)
  ;;(c:test_1)
  ;; ElpanovEvgeniy
  (defun pars (s f f1)
    (if s
      (progn
        ((lambda (l)
           (if (< (car l) (cadr l))
             (min_max (car l) (cadr l) (cddr l) f1)
             (min_max (cadr l) (car l) (cddr l) f1)
           ) ;_ if
         ) ;_ lambda
          (read (strcat "(" (VL-STRING-TRANSLATE "," " " s) ")"))
        )
        (pars (read-line f) f f1)
      ) ;_ progn
      (progn
        (close f)
        (close f1)
      ) ;_ progn
    ) ;_ if
  ) ;_ defun
  (defun min_max (mi ma l f)
    (if l
      (if (< (car l) mi)
        (min_max (car l) ma (cdr l) f)
        (if (> (car l) ma)
          (min_max mi (car l) (cdr l) f)
          (min_max mi ma (cdr l) f)
        ) ;_ if
      ) ;_ if
      (write-line (strcat (itoa mi) " " (itoa ma)) f)
    ) ;_ if
  ) ;_ defun
  (setq timer (getvar "millisecs"))
  (pars (read-line (setq f (open "D:\\numbers.csv" "R"))) f (open "D:\\result.csv" "W"))
  (princ
    (strcat
      "Process took "
      (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 4)
      " seconds."
    ) ;_ strcat
  ) ;_ princ
  (princ)
) ;_ defun

(defun c:test_2 (/ f f1 timer)
  ;;(c:test_2)
  ;; ElpanovEvgeniy
  (defun pars (s f)
    (if s
      (cons (read (strcat "(" (VL-STRING-TRANSLATE "," " " s) ")"))
            (pars (read-line f) f)
      ) ;_ cons
      (close f)
    ) ;_ if
  ) ;_ defun
  (defun min_max (mi ma l f)
    (if l
      (if (< (car l) mi)
        (min_max (car l) ma (cdr l) f)
        (if (> (car l) ma)
          (min_max mi (car l) (cdr l) f)
          (min_max mi ma (cdr l) f)
        ) ;_ if
      ) ;_ if
      (write-line (strcat (itoa mi) " " (itoa ma)) f)
    ) ;_ if
  ) ;_ defun
  (setq timer (getvar "millisecs"))
  (setq f1 (open "D:\\numbers.csv" "R"))
  (setq f (open "D:\\result.csv" "W"))
  (foreach l (pars (read-line f1) f1)
    (if (< (car l) (cadr l))
      (min_max (car l) (cadr l) (cddr l) f)
      (min_max (cadr l) (car l) (cddr l) f)
    ) ;_ if
  ) ;_ foreach
  (close f)
  (princ
    (strcat
      "Process took "
      (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 4)
      " seconds."
    ) ;_ strcat
  ) ;_ princ
  (princ)
) ;_ defun

(defun c:max-min (/ file1 file2 lin linlist max1 min1 timer)
  ;;(c:max-min)
  ;;Jeff_M
  (defun Split (str / i j lst)
    (setq i 0)
    (while (setq j (vl-string-search "," str i))
      (setq lst (cons (substr str (1+ i) (- j i)) lst)
            i   (1+ j)
      ) ;_ setq
    ) ;_ while
    (reverse (cons (substr str (1+ i)) lst))
  ) ;_ defun
;;;main function
  (setq timer (getvar "millisecs"))
  (if
    (setq
      file1 (open "D:\\numbers.csv" "R")
    ) ;_ setq
     (progn
       (setq file2
              (open "D:\\results.csv"
                    "W"
              ) ;_ open
       ) ;_ setq
       (while (setq lin (read-line file1))
         (setq linlist (mapcar 'atoi (split lin)))
         (setq min1 (apply 'min linlist)
               max1 (apply 'max linlist)
         ) ;_ setq
         (write-line (strcat (itoa max1) "," (itoa min1)) file2)
       ) ;_ while
       (close file1)
       (close file2)
       (princ
         (strcat "Process took "
                 (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2)
                 " seconds."
         ) ;_ strcat
       ) ;_ princ
     ) ;_ progn
  ) ;_ if
  (princ)
) ;_ defun
(defun c:minmax (/ #HI #LOW F1 L1 LINEM NEWFILE TIMER)
  ;;(c:minmax)
  ;; Andrea
  (setq timer (getvar "millisecs"))
  (setq f1 (open "D:\\numbers.csv"
                 "r"
           ) ;_ open
        l1 (read-line f1)
  ) ;_ setq
  (if l1
    (setq newfile (open "D:\\result.txt" "w"))
  ) ;_ if
  (while l1
    (setq lineM (read (strcat "(" (acet-str-replace "," " " l1) ")"))
          #low  (car (vl-sort lineM '<))
          #hi   (car (vl-sort lineM '>))
    ) ;_ setq
    (write-line (strcat (rtos #hi) " " (rtos #low)) newfile)
    (setq l1 (read-line f1))
  ) ;_ while
  (close f1)
  (close newfile)
  (princ
         (strcat "Process took "
                 (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2)
                 " seconds."
         ) ;_ strcat
       )
 
  (princ)
) ;_ defun

(defun c:test (/ FILEBASE FILEDATA FILENAME HANDLE LST PATH STREAM)
  ;; CAB
  ;;(c:test)
  (defun sparser1 (str delim / ptr lst)
    ;;  parser by CAB 
    (while (setq ptr (vl-string-search delim str))
      (setq lst (cons (substr str 1 ptr) lst))
      (setq str (substr str (+ ptr 2)))
    ) ;_ while
    (reverse (cons str lst))
  ) ;_ defun
  (setq timer (getvar "millisecs"))
  (if
    (and
      (setq filename "D:\\numbers.csv")
      (setq handle (open filename "r"))
    ) ;_ and
     (progn
       (while (setq stream (read-line handle))
         (setq FileData (cons stream FileData))
       )                                ; while
       (close handle)
     ) ;_ progn
  ) ;_ if
  (if FileData
    (progn
      (setq path     (vl-filename-directory filename)
            filebase (vl-filename-base filename)
            handle   (open (strcat path "\\" filebase "-out.csv") "w")
      ) ;_ setq
      (mapcar
        (function
          (lambda (x)
            (setq lst
                   (mapcar
                     (function
                       (lambda (y)
                         (atoi y)
                       ) ;_ lambda
                     ) ;_ function
                     (sparser1 x ",")
                   ) ;_ mapcar
            ) ;_ setq
            (princ (apply 'max lst) handle)
            (princ "-" handle)
            (princ (apply 'min lst) handle)
            (princ "\n" handle)
          ) ;_ lambda
        ) ;_ function
        FileData
      ) ;_ mapcar
      (close handle)
      (princ
        (strcat "Process took "
                (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2)
                " seconds."
        ) ;_ strcat
      ) ;_ princ
    ) ;_ progn
  ) ;_ if
  (princ)
) ;_ defun


Check:

Code: [Select]
(c:test) ;; CAB
(c:minmax) ;; Andrea
(c:max-min) ;;Jeff_M
(c:test_2) ;; ElpanovEvgeniy
(c:test_1) ;; ElpanovEvgeniy

;
 VLX-Application packed D:/Work/Project/lib/test/test.VLX
_$
Process took 0.83 seconds.
 Process took 1.67 seconds.
 Process took 0.84 seconds.
 Process took 0.469 seconds.
 Process took 0.5 seconds.


check 2
_$
Process took 0.81 seconds.
 Process took 1.66 seconds.
 Process took 0.88 seconds.
 Process took 0.469 seconds.
 Process took 0.5 seconds.
 
check 3
_$
Process took 0.83 seconds.
 Process took 1.64 seconds.
 Process took 0.88 seconds.
 Process took 0.453 seconds.
 Process took 0.5 seconds.
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/

CAB

  • Global Moderator
  • Seagull
  • Posts: 10366
Re: ( Challenge ) Just curious
« Reply #22 on: December 02, 2006, 07:39:11 AM »
Evgeniy,
Very fast, I see that vl-string-translate makes a huge deference.
Thanks  :-)

I revised mine & cut the time here in half.

Code: [Select]
;;  CAB Revised
(defun c:test2 (/ FILEBASE FILEDATA FILENAME HANDLE LST PATH STREAM
               sparser)
  (setq timer (getvar "millisecs"))

  (if
    (and
      (setq filename (findfile "numbers.csv"))
      (setq handle (open filename "r"))
    )
     (progn
       (while (setq stream (read-line handle))
         (setq FileData (cons stream FileData))
       ) ; while
       (close handle)
     )
  )

  (if FileData
    (progn
      (setq path     (vl-filename-directory filename)
            filebase (vl-filename-base filename)
            handle   (open (strcat path "\\" filebase "-out.csv") "w")
      )
      (mapcar
        (function
          (lambda (x)
            (setq lst (read (strcat "(" (vl-string-translate "," " " x) ")")))
            (princ (apply 'max lst) handle)
            (princ "-" handle)
            (princ (apply 'min lst) handle)
            (princ "\n" handle)
          )
        )
        FileData
      )
      (close handle)
      (princ (strcat "Process took "
                     (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2)
                     " seconds."
             )
      )

    )
  )

  (princ)
)
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: 10366
Re: ( Challenge ) Just curious
« Reply #23 on: December 02, 2006, 07:53:26 AM »
Evgeniy,
Looking more at your routine I suspect the recursive min_max may be faster than
(apply 'max lst) but I haven't tested that. 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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1540
  • Moscow (Russia)
Re: ( Challenge ) Just curious
« Reply #24 on: December 02, 2006, 08:03:03 AM »

 :-)
Code: [Select]
(c:test2) ;; CAB Revised
(c:test) ;; CAB
(c:minmax) ;; Andrea
(c:max-min) ;;Jeff_M
(c:test_2) ;; ElpanovEvgeniy
(c:test_1) ;; ElpanovEvgeniy

;
 VLX-Application packed D:/Work/Project/lib/test/test.VLX
 
_$
Process took 0.44 seconds.
 Process took 0.86 seconds.
 Process took 1.81 seconds.
 Process took 0.8 seconds.
 Process took 0.469 seconds.
 Process took 0.5 seconds.
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/

CAB

  • Global Moderator
  • Seagull
  • Posts: 10366
Re: ( Challenge ) Just curious
« Reply #25 on: December 02, 2006, 08:13:52 AM »
Thanks you Sir.
My test were similar, relatively speaking.
Your fastest version I suspect must be that you simulated the APPLY MIN MAX with your
faster code. Very nice! :-)
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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1540
  • Moscow (Russia)
Re: ( Challenge ) Just curious
« Reply #26 on: December 02, 2006, 08:42:23 AM »
new version...
 :-)
Code: [Select]
(defun c:test_3 (/ f f1 timer)
  ;;(c:test_2)
  ;; ElpanovEvgeniy
  (defun pars (s f)
    (if s
      (cons (read (strcat "(" (VL-STRING-TRANSLATE "," " " s) ")"))
            (pars (read-line f) f)
      ) ;_ cons
      (close f)
    ) ;_ if
  ) ;_ defun
  (defun min_max (mi ma l f)
    (if l
      (if (< (car l) mi)
        (min_max (car l) ma (cdr l) f)
        (if (> (car l) ma)
          (min_max mi (car l) (cdr l) f)
          (min_max mi ma (cdr l) f)
        ) ;_ if
      ) ;_ if
      (strcat (itoa mi) " " (itoa ma) "\n")
    ) ;_ if
  ) ;_ defun
  (setq timer (getvar "millisecs"))
  (setq f1 (open "D:\\numbers.csv" "R"))
  (setq f (open "D:\\result.csv" "W"))
  (princ
    (apply
      (function strcat)
      (mapcar
        (function
          (lambda (l)
            (if (< (car l) (cadr l))
              (min_max (car l) (cadr l) (cddr l) f)
              (min_max (cadr l) (car l) (cddr l) f)
            ) ;_ if
          ) ;_ lambda
        ) ;_ function
        (pars (read-line f1) f1)
      ) ;_ mapcar
    ) ;_ apply
    f
  ) ;_ princ
  (close f)
  (princ
    (strcat
      "Process took "
      (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 4)
      " seconds."
    ) ;_ strcat
  ) ;_ princ
  (princ)
) ;_ defun

Check:

Code: [Select]
(c:test2) ;; CAB Revised
(c:test_2) ;; ElpanovEvgeniy
(c:test_3) ;; ElpanovEvgeniy

;
 VLX-Application packed D:/Work/Project/lib/test/test.VLX
 
_$
Process took 0.47 seconds.
 Process took 0.5 seconds.
 Process took 0.406 seconds.
蝸牛そろそろ登れ富士の山 /Kobayashi Issa/

Mark

  • Custom Title
  • Seagull
  • Posts: 28685
Re: ( Challenge ) Just curious
« Reply #27 on: December 02, 2006, 08:50:21 AM »
You guys never fail to amaze me! :-)
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10366
Re: ( Challenge ) Just curious
« Reply #28 on: December 02, 2006, 09:02:16 AM »
Evgeniy you're about the break the 'Sound Barrier'  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.

Andrea

  • Water Moccasin
  • Posts: 2360
Re: ( Challenge ) Just curious
« Reply #29 on: December 02, 2006, 09:08:12 AM »
wOo !...

i'm the slowest... ^-^

do i win something ?... :-D
Keep smile...