1. append() versus &=
- Posted by Lewis Townsend <keroltarr at HOTMAIL.COM> Sep 12, 2000
- 433 views
- Last edited Sep 13, 2000
Hello, Who was it that recently said that append() is faster than &= ? I have written a benchmark program that seems to prove otherwise. Let me know if there is a flaw in my program or if I misunderstood or what. ----- TESTED CODE ------- constant its = 100000 sequence s atom t object temp constant frmt = "%0.03f" printf (1, "Appending benchmarks for Euphoria using %d iterations\n", its) puts (1, "\nAppending integers...\n") puts (1, "append():\t") s = {} t=time() for i = 1 to its do s = append (s, rand (its)) end for t = time() - t printf (1, frmt & "\n", t) puts (1, "&=:\t\t") s = {} t = time () for i = 1 to its do s &= rand (its) end for t = time() - t printf (1, frmt & "\n", t) constant chars = 20 printf (1, "\nAppending strings (%d characters)...\n", chars) puts (1, "append():\t") s = {} temp = repeat (255,chars) t=time() for i = 1 to its do s = append (s, rand (temp)) end for t = time() - t printf (1, frmt & "\n", t) puts (1, "&=:\t\t") s = {} t = time () for i = 1 to its do s &= {rand (temp)} end for t = time() - t printf (1, frmt & "\n", t) puts (1, "\nAppending complex sequences eg: {a,{a,{a}}}...\n") puts (1, "append():\t") s = {} temp = {its,{its,{its}}} t=time() for i = 1 to its do s = append (s, rand (temp)) end for t = time() - t printf (1, frmt & "\n", t) puts (1, "&=:\t\t") s = {} t = time () for i = 1 to its do s &= {rand (temp)} end for t = time() - t printf (1, frmt & "\n", t) -------END CODE------- later, Lewis Townsend _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. Share information about yourself, create your own public profile at http://profiles.msn.com.
2. Re: append() versus &=
- Posted by Robert Craig <rds at ATTCANADA.NET> Sep 12, 2000
- 413 views
- Last edited Sep 13, 2000
Lewis Townsend writes: > Who was it that recently said that append() is faster > than &= ? I have written a benchmark program that > seems to prove otherwise. Let me know if there is a flaw > in my program or if I misunderstood or what. Try your benchmark again, but this time run each append() loop *after* the corresponding &= loop. I think you'll be surprised. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
3. Re: append() versus &=
- Posted by jiri babor <jiri_babor at HOTMAIL.COM> Sep 13, 2000
- 429 views
Lewis, I am probably too dense, but Robert's reply was not of much help, as far as I am concern... I think your benchmark is completely dominated by the troublesome rand() function. Take it out of the loop and you will see Rob indeed optimised the common case: s1 = append(s1, s2) I modified your code slightly, improving the timer resolution and bumping the iterations up too: include machine.e -- tick_rate() constant its = 1000000 constant frmt = "%0.03f" constant chars = 20 sequence s,temp atom t integer rits rits = rand(its) tick_rate(200) printf (1, "Appending benchmarks for Euphoria using %d iterations\n", its) puts (1, "\nAppending integers again...\n") puts (1, "append():\t") s = {} t=time() for i = 1 to its do s = append (s, rits) end for t = time() - t printf (1, frmt & "\n", t) puts (1, "&=:\t\t") s = {} t = time () for i = 1 to its do s &= rits end for t = time() - t printf (1, frmt & "\n", t) printf (1, "\nAppending strings (%d characters)...\n", chars) puts (1, "append():\t") s = {} temp = rand(repeat (255,chars)) t=time() for i = 1 to its do s = append (s, temp) end for t = time() - t printf (1, frmt & "\n", t) puts (1, "&=:\t\t") s = {} t = time () for i = 1 to its do s &= {temp} end for t = time() - t printf (1, frmt & "\n", t) puts (1, "\nAppending complex sequences eg: {a,{a,{a}}}...\n") puts (1, "append():\t") s = {} temp = rand({its,{its,{its}}}) t=time() for i = 1 to its do s = append (s, temp) end for t = time() - t printf (1, frmt & "\n", t) puts (1, "&=:\t\t") s = {} t = time () for i = 1 to its do s &= {temp} end for t = time() - t printf (1, frmt & "\n", t) _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. Share information about yourself, create your own public profile at http://profiles.msn.com.
4. Re: append() versus &=
- Posted by Robert Craig <rds at ATTCANADA.NET> Sep 13, 2000
- 435 views
Jiri Babor writes: > I am probably too dense, but Robert's reply was not of much help, > as far as I am concern... In Lewis Townsend's program I found a big difference in the timing of the last two (more complicated) tests, depending on whether I moved the append() loop before or after the corresponding &= loop. It's complicated, but I think it has to do with the pattern of dynamic storage allocation. I didn't find this with your modified version. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
5. Re: append() versus &=
- Posted by Lewis Townsend <keroltarr at HOTMAIL.COM> Sep 13, 2000
- 440 views
Hello Rob, Jiri I did try switching the parts arround and it did make a difference. But either way, append() was still slower on the "complex" append. >I think your benchmark is completely dominated by the troublesome rand() >function. Take it out of the loop and you will see Rob indeed optimised the >common case: > s1 = append(s1, s2) I used rand() to add some variation in the data because otherwise cacheing occurs which speeds up things in a seemingly unpredictable way. I can't think of any useful program (off the top of my head) that would simply append thousands of identical items to each other. Besides, I don't see how rand() was messing up the numbers since I always did the same thing in both loops. Perhaps an assignment and THEN the append would work better. I am currently working on 2 projects: LOOP (an OOP lib) and a real-time game. Both will need all the speed they can get and both will be operating on complex sequences with plenty of randomness. I felt that my benchmarks adequately tested for speed in this situation but perhaps not. I have tried testing LOOP lib itself with either all append()s or all &=s. Sometimes one seems faster and sometimes the other. I want to use the one that's faster MOST of the time but I think your (jiri's) program allows data caching to invalidate the benchmarks. I'm not sure WHAT was going on with mine that always gave the second loop an advantage but I'd like to know how to accurately test for the speed of random complex data appending. Jiri, I'm sure you can come up with something. I wouldn't just wait for you to do all the work but I wont' be able to do any coding until after this weekend as I'll be away from my comp for 4 days. later, Lewis Townsend _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. Share information about yourself, create your own public profile at http://profiles.msn.com.