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

0 Members and 1 Guest are viewing this topic.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: ( Challenge ) Just curious
« Reply #60 on: December 04, 2006, 11:37:20 AM »
Evgeniy
Looking at your Test4, and others I see you reading a line from the file, then processing it before
reading another line. I thought it would be faster to read the entire file into a list & then process
the list. Now that I think about it, I suppose that the disk speed & disk cashing would play a part
in that, as well as how long the data processing took.

No..
for Test_4
I all over again read all file, and then it I process MAPCAR...
Code: [Select]
(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

http://www.theswamp.org/index.php?topic=13771.0
I read and at once I process what to not read all file - he too long....

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ( Challenge ) Just curious
« Reply #61 on: December 04, 2006, 12:19:37 PM »
OK, i see, but I would call that a split process as you do convert the incoming data to a list of numbers
line by line before the mapcar to get min / max.

I tried to test it but my timing varied so I'm not sure of the results.


Code: [Select]
(defun c:test_5 (/ f f1 timer ldata data)
  ;;(c:test_5)
  ;; ElpanovEvgeniy - Modified
  (defun min_max (mi ma l f)
    (if l
      (if (< mi (car l) ma)
        (min_max mi ma (cdr l) f)
        (if (< (car l) mi)
          (min_max (car l) ma (cdr l) f)
          (min_max mi (car l) (cdr l) f)
        ) ;_ if
      ) ;_ if
      (strcat (itoa mi) " " (itoa ma) "\n")
    ) ;_ if
  ) ;_ defun
  (setq timer (getvar "millisecs"))
  (setq f1 (open "c:\\numbers.csv" "R"))
  (while (setq ldata (read-line f1))
    (setq data (cons ldata data))
  )
  (close f1)
  (setq f (open "c:\\result.csv" "W"))
  (princ
    (apply
      (function strcat)
      (mapcar
        (function
          (lambda (l)
            (setq l (read (strcat "(" (vl-string-translate "," " " 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
        data
      ) ;_ mapcar
    ) ;_ apply
    f
  ) ;_ princ
  (close f)
  (princ
    (strcat
      "Process took "
      (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 4)
      " seconds."
    ) ;_ strcat
  ) ;_ princ
  (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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: ( Challenge ) Just curious
« Reply #62 on: December 04, 2006, 12:35:51 PM »
OK, i see, but I would call that a split process as you do convert the incoming data to a list of numbers
line by line before the mapcar to get min / max.

I tried to test it but my timing varied so I'm not sure of the results.



At me exact results have failed...
See.



Code: [Select]
(c:test_3) ;; ElpanovEvgeniy
(c:test_4) ;; ElpanovEvgeniy
(c:test_5) ;; CAB - Modified


Process took 0.359 seconds.
 Process took 0.344 seconds.
 Process took 0.375 seconds.
 
_$
Process took 0.36 seconds.
 Process took 0.359 seconds.
 Process took 0.375 seconds.
 
_$
Process took 0.375 seconds.
 Process took 0.36 seconds.
 Process took 0.359 seconds.
 
_$

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ( Challenge ) Just curious
« Reply #63 on: December 04, 2006, 12:46:50 PM »
Yes, I could not get exact results.
My computer :

Command: test_4
Process took 0.7810 seconds.
TEST_4 Process took 0.7710 seconds.
TEST_4 Process took 0.7810 seconds.
TEST_4 Process took 0.7810 seconds.
TEST_4 Process took 0.7810 seconds.
TEST_4 Process took 0.7810 seconds.
TEST_4 Process took 0.7810 seconds.

Command:
Command: test_5
Process took 0.7410 seconds.
TEST_5 Process took 0.7610 seconds.
TEST_5 Process took 0.7910 seconds.
TEST_5 Process took 0.7510 seconds.
TEST_5 Process took 0.7810 seconds.
TEST_5 Process took 0.7910 seconds.
TEST_5 Process took 0.7510 seconds.

test 4 had steady results while the test 5 varied. Not sure why.
But there seems to be no real advantage in doing it with the WHILE in test5.
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ( Challenge ) Just curious
« Reply #64 on: December 04, 2006, 01:29:19 PM »
Here is mine based off what you two (Evgeniy and Alan) are doing.  I didn't think it would be that much of a difference, but it is.  Thanks for the showing.
Code: [Select]
(defun c:HiLow (/ File Opened TextLine TextList NumList Timer NewOpened NewFile MinNum MaxNum Num Pos StPos Str)

(if
 (and
;  (setq File (getfiled "" "" "csv" 4))
  (setq Timer (StartTimer))
  (setq Opened (open "c:/test/numbers.csv" "r"))
  (setq NewOpened (open "c:/test/results.csv" "w"))
;  (setq Opened (open File "r"))
;  (setq NewFile (strcat (vl-filename-directory File) "\\Returned.csv"))
;  (setq NewOpened (open NewFile "w"))
 )
 (progn
  (while (setq TextLine (read-line Opened))
   (function
    (lambda (/ MinNum MaxNum)
     (setq cnt 0)
     (mapcar
      '(lambda (x / Num)
       (if (or (not MinNum) (> MinNum Num))
        (setq MinNum Num)
       )
       (if (or (not MaxNum) (< MaxNum Num))
        (setq MaxNum Num)
       )
      )
      (read (strcat "(" (vl-string-translate "," " " TextLine) ")"))
     )
     (princ (strcat (itoa MinNum) "," (itoa MaxNum) NewOpened))
    )
   )
  )
  (close Opened)
  (close NewOpened)
  (prompt (EndTimer Timer))
 )
)
(princ)
)
Quote
Command: hilow

 Elasped time 0.016000 seconds.
Command:
Command: hilow

 Elasped time 0.047000 seconds.
Command:
Command:
HILOW
 Elasped time 0.016000 seconds.
Command:
Command:
HILOW
 Elasped time 0.016000 seconds.
Command:
Command:
HILOW
 Elasped time 0.031000 seconds.
Command:
Command:
HILOW
 Elasped time 0.031000 seconds.
Command:
Command:
HILOW
 Elasped time 0.015000 seconds.
Command:
Command:
HILOW
 Elasped time 0.047000 seconds.
Command:
Tim

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

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ( Challenge ) Just curious
« Reply #65 on: December 04, 2006, 01:49:34 PM »
Tim,
The Results.csv is empty. :-)
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ( Challenge ) Just curious
« Reply #66 on: December 04, 2006, 02:35:35 PM »
Tim,
The Results.csv is empty. :-)
Stupid parenthesis!!!  Here is one that works.
Code: [Select]
(defun c:HiLow (/ Opened TextLine Timer NewOpened MinNum MaxNum Num)

(if
 (and
  (setq Timer (StartTimer))
  (setq Opened (open "c:/test/numbers.csv" "r"))
  (setq NewOpened (open "c:/test/results.csv" "w"))
 )
 (progn
  (while (setq TextLine (read-line Opened))
   (
    (lambda (/ MinNum MaxNum)
     (mapcar
      '(lambda (Num)
       (if (or (not MinNum) (> MinNum Num))
        (setq MinNum Num)
       )
       (if (or (not MaxNum) (< MaxNum Num))
        (setq MaxNum Num)
       )
      )
      (read (strcat "(" (vl-string-translate "," " " TextLine) ")"))
     )
     (princ (strcat (itoa MinNum) "," (itoa MaxNum) "\n") NewOpened)
    )
   )
  )
  (close Opened)
  (close NewOpened)
  (prompt (EndTimer Timer))
 )
)
(princ)
)
Not as fast as your guys stuff, but still a lot faster than my other one, here are the times.
Quote
Command: hilow

 Elasped time 0.578000 seconds.
Command:
Command:
HILOW
 Elasped time 0.594000 seconds.
Command:
Command:
HILOW
 Elasped time 0.609000 seconds.
Command:
Command:
HILOW
 Elasped time 0.609000 seconds.
Command:
Command:
HILOW
 Elasped time 0.594000 seconds.
Command:
Command:
HILOW
 Elasped time 0.609000 seconds.

Side note: 'princ'ing to a file , with adding a new line to the string, is faster than useing 'write-line' to the file.  It shaved off about 1/10 sec.
Tim

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

Please think about donating if this post helped you.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: ( Challenge ) Just curious
« Reply #67 on: December 04, 2006, 02:45:31 PM »

Not as fast as your guys stuff, but still a lot faster than my other one, here are the times.


It is not known, for whom works faster...  :-)
Try to look, it is what is the time fulfilled TEST_4 on your computer then it will be possible to compare!

Speed for all different

CAB
TEST_4 = 0.7710 seconds
ElpanovEvgeniy (work)
TEST_4 = 0.344 seconds.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ( Challenge ) Just curious
« Reply #68 on: December 04, 2006, 02:51:36 PM »
Evgeniy - test_4
Quote
Command: test_4
Process took 0.4370 seconds.

Command:
Command:
TEST_4 Process took 0.4070 seconds.

Command:
Command:
TEST_4 Process took 0.4060 seconds.

Command:
Command:
TEST_4 Process took 0.3750 seconds.

Command:
TEST_4 Process took 0.4060 seconds.

Command:
Command:
TEST_4 Process took 0.4380 seconds.

Alan - test_5
Quote
Command: test_5
Process took 0.4220 seconds.

Command:
Command:
TEST_5 Process took 0.4530 seconds.

Command:
Command:
TEST_5 Process took 0.4530 seconds.

Command:
Command:
TEST_5 Process took 0.4690 seconds.

Command:
Command:
TEST_5 Process took 0.4220 seconds.

Mine - hilow
Quote
Command: hilow

 Elasped time 0.594000 seconds.
Command:
Command:
HILOW
 Elasped time 0.594000 seconds.
Command:
Command:
HILOW
 Elasped time 0.609000 seconds.
Command:
Command:
HILOW
 Elasped time 0.562000 seconds.
Command:
Tim

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

Please think about donating if this post helped you.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: ( Challenge ) Just curious
« Reply #69 on: December 04, 2006, 02:58:34 PM »
Evgeniy   - test_4
CAB        - test_5
T.Willey   - hilow

I think, our score identical...
Drawn game? :-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: ( Challenge ) Just curious
« Reply #70 on: December 04, 2006, 03:12:42 PM »
In my book you would win.  My was over two seconds first, only after I copied your routine (to help me understand it) did my time come down to yours.  Thanks for the lesson Evgeniy, I learned something new!!  This has been fun.
Tim

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

Please think about donating if this post helped you.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: ( Challenge ) Just curious
« Reply #71 on: December 04, 2006, 03:16:23 PM »

In my book.......


You write the book?

LE

  • Guest
Re: ( Challenge ) Just curious
« Reply #72 on: December 04, 2006, 03:22:53 PM »

In my book.......


You write the book?


Evgeniy;

Это - способ сказать на английском языке, что Вы очень шикарны

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: ( Challenge ) Just curious
« Reply #73 on: December 04, 2006, 03:29:18 PM »

Evgeniy;

Это - способ сказать на английском языке, что Вы очень шикарны


Luis, you do not cease to surprise me!
You know Russian? (I do not trust, that the previous message has been translated by the program)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: ( Challenge ) Just curious
« Reply #74 on: December 04, 2006, 03:31:45 PM »
In my book you would win.  My was over two seconds first, only after I copied your routine (to help me understand it) did my time come down to yours.  Thanks for the lesson Evgeniy, I learned something new!!  This has been fun.

Thanks!
To me it is very pleasant  :-)