Author Topic: Place your bets (process evaluation time)  (Read 9203 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Place your bets (process evaluation time)
« Reply #15 on: December 30, 2006, 11:13:15 AM »
Perhaps my statement was way too broad as the right tool for the job yields the most efficient method.
Here is another series of test routines.

Code: [Select]
(if (null *List@)
  (repeat 10
      (setq Cnt# 48)
      (repeat 100
        (setq *List@ (append *List@ (list (chr Cnt#))))
        (setq Cnt# (1+ Cnt#))
      )
    )
)

(defun c:test ()
  (BenchMark
    '((apples *List@)
      (oranges *List@)
      (pears *List@)
      (bananas *List@)
     )
  )
)


(defun apples (lst)
  (while lst
    (if (= (car lst) "Z")
      (print "Found")
      )
    (setq lst (cdr lst))
  )
)

(defun oranges (lst)
  (repeat (length lst)
    (if (= (car lst) "Z")
      (print "Found")
      )
    (setq lst (cdr lst))
  )
)

(defun pears (lst)
  (mapcar '(lambda (x) (if (= x "Z")(print "Found"))) lst)
)

(defun bananas (lst)
  (foreach itm lst
    (if (= itm "Z")
      (print "Found")
      )
  )
)

Code: [Select]
Elapsed milliseconds / relative speed for 256 iteration(s):

    (PEARS *LIST@).......1392 / 1.22 <fastest>
    (APPLES *LIST@)......1462 / 1.16
    (BANANAS *LIST@).....1472 / 1.16
    (ORANGES *LIST@).....1703 / 1.00 <slowest>


Funny how REPEAT is still last.
How would you account for that?
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.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8858
  • AKA Daniel
Re: Place your bets (process evaluation time)
« Reply #16 on: December 30, 2006, 11:26:01 AM »
Funny though I get pears as the slowest on my machine
Dan


myresults .. in seconds

Code: [Select]
;;apples 1.162
;;oranges 1.792
;;pears 1.883
;;bananas 1.242

added I have always been an apples and bananas kind of guy anyway
Interesting though
« Last Edit: December 30, 2006, 11:36:46 AM by Danielm103 »

Chuck Gabriel

  • Guest
Re: Place your bets (process evaluation time)
« Reply #17 on: December 30, 2006, 11:42:25 AM »
For reference:

Code: [Select]
Elapsed milliseconds / relative speed for 512 iteration(s):

    (PEARS *LIST@).......1360 / 1.36 <fastest>
    (APPLES *LIST@)......1531 / 1.20
    (BANANAS *LIST@).....1532 / 1.20
    (ORANGES *LIST@).....1844 / 1.00 <slowest>

Uncompiled code, in AutoCAD 2000i, on an Athlon XP 3000+, with 1 GB of RAM.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Place your bets (process evaluation time)
« Reply #18 on: December 30, 2006, 11:43:09 AM »
That is strange Dan, how your machine differs from mine in the order of the results.
Hope someone can shed some light on Why?
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.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8858
  • AKA Daniel
Re: Place your bets (process evaluation time)
« Reply #19 on: December 30, 2006, 12:36:12 PM »
That is strange Dan, how your machine differs from mine in the order of the results.
Hope someone can shed some light on Why?


sure is,   this is using the STD benchmark tool

    (APPLES *LIST@)......1722 / 1.26 <fastest>
    (BANANAS *LIST@).....1833 / 1.19
    (ORANGES *LIST@).....2073 / 1.05
    (PEARS *LIST@).......2173 / 1 <slowest>

added Acad 2007, winxp sp2, 1gig amd, 1gig ram
« Last Edit: December 30, 2006, 12:45:22 PM by Danielm103 »

daron

  • Guest
Re: Place your bets (process evaluation time)
« Reply #20 on: December 30, 2006, 04:22:58 PM »
Well, the only thing I can assume of why repeat is slower than while is the fact that repeat has an extra step of counting all the items at once before running the process each time, where the while loop sets each item to ssname and doesn't have to count at all, just take note of when T becomes nil. Also, while removes a step from repeat because of the setting of ssname to its test function. Depending on how much work it has to do, I'd think that the speed would vary. Try this test. Set up your routine with say 50 items, then with 100 items, then with 1000 items and see what the variations of the speed are. What I think should be seen is that the more items you have, the further apart the times get from each other. The more tests run, should produce an interesting time graph.

Note: If my memory serves, the above test could be skewed by the slowing of code used repetitively. You might check to see if the times change on the same number of objects using multiple passes and possibly take into account the time differential.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Place your bets (process evaluation time)
« Reply #21 on: December 30, 2006, 06:10:34 PM »
Daron,
The REPEAT only looks at the (length lst) one time at the beginning of the command and never again.
It must maintain an internal counter.
You can see it in this example:
Code: [Select]
(defun c:test ()
  (setq lst '(1 2 3 4 5 6 7 8 9))
  (repeat (length lst)
    (setq lst nil)
    (print lst)
  )
  (princ)
)

Command: test

nil
nil
nil
nil
nil
nil
nil
nil
nil
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: Place your bets (process evaluation time)
« Reply #22 on: December 30, 2006, 06:16:08 PM »
Oh, are you referring to the extra (length lst)
Look at this test:
Code: [Select]
(defun apples (lst)
  (length lst)
  (while lst
    (if (= (car lst) "Z")
      (print "Found")
      )
    (setq lst (cdr lst))
  )
)

(defun oranges (lst)
  (repeat (length lst)
    (if (= (car lst) "Z")
      (print "Found")
      )
    (setq lst (cdr lst))
  )
)
Code: [Select]
Elapsed milliseconds / relative speed for 256 iteration(s):

    (APPLES *LIST@)......1532 / 1.16 <fastest>
    (ORANGES *LIST@).....1783 / 1.00 <slowest>
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Place your bets (process evaluation time)
« Reply #23 on: December 30, 2006, 07:17:42 PM »
This is a really unusual anomaly

Pears do it for me too ..
Quote
Elapsed milliseconds for 128 iteration(s)/ relative Timing :

    (ORANGES *LIST@).....2078 / 2.0453 <slowest>
    (BANANAS *LIST@).....1625 / 1.5994
    (APPLES *LIST@)......1484 / 1.4606
    (PEARS *LIST@).......1016 / 1 <fastest>

added:
on Acad2007, winxp sp2, Dual Pentium 3.4GHz Intel, 1GHz ram
« Last Edit: December 30, 2006, 07:24:49 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8858
  • AKA Daniel
Re: Place your bets (process evaluation time)
« Reply #24 on: December 30, 2006, 09:27:33 PM »
Hmm I changed the order of the test and ran it compiled to an fas

Code: [Select]
Elapsed milliseconds / relative speed for 1024 iteration(s):
(BANANAS *LIST@).....1503 / 1.51 <fastest>
(APPLES *LIST@)......1883 / 1.21
(ORANGES *LIST@).....2063 / 1.1
(PEARS *LIST@).......2273 / 1 <slowest>

oh well it's an AMD

maybe its the iterations?
« Last Edit: December 30, 2006, 09:29:06 PM by Danielm103 »

Joe Burke

  • Guest
Re: Place your bets (process evaluation time)
« Reply #25 on: December 31, 2006, 01:31:53 PM »
Oh, are you referring to the extra (length lst)
Look at this test:
Code: [Select]
(defun apples (lst)
  (length lst)
  (while lst
    (if (= (car lst) "Z")
      (print "Found")
      )
    (setq lst (cdr lst))
  )
)

(defun oranges (lst)
  (repeat (length lst)
    (if (= (car lst) "Z")
      (print "Found")
      )
    (setq lst (cdr lst))
  )
)
Code: [Select]
Elapsed milliseconds / relative speed for 256 iteration(s):

    (APPLES *LIST@)......1532 / 1.16 <fastest>
    (ORANGES *LIST@).....1783 / 1.00 <slowest>

Check me. This feels like a flawed test.

Therr's no reason for the (setq lst (cdr lst)) call within the repeat function. Whereas it serves an obvious purpose within a while loop.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Place your bets (process evaluation time)
« Reply #26 on: December 31, 2006, 02:19:32 PM »
The idea was to compare the WHILE & REPEAT so I kept the routines as similar as I could.
You could use an index pointer & NTH in the REPEAT version I suppose.
How would you set up a comparison?
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.

Joe Burke

  • Guest
Re: Place your bets (process evaluation time)
« Reply #27 on: January 02, 2007, 08:55:00 AM »
The idea was to compare the WHILE & REPEAT so I kept the routines as similar as I could.
You could use an index pointer & NTH in the REPEAT version I suppose.
How would you set up a comparison?

CAB,

I tried rereading this topic. I'm totally lost now.

I see your point regarding while and repeat as quoted here. But I would probably use foreach in such a case. Regardless of whether it is faster or slower than the other methods. Because it is the obvious way to iterate through a list without destroying the source list in the process.

Regards