| www.ClassicTW.com https://mail.black-squirrel.com/ |
|
| Speed question https://mail.black-squirrel.com/viewtopic.php?f=15&t=16956 |
Page 1 of 1 |
| Author: | Promethius [ Thu Feb 02, 2006 7:54 pm ] |
| Post subject: | |
In trying to speed a script up, which of the two snippets below would be faster? The variables $x and $y will always be either 1 or 2 and both are initialized and then changes are made with the snippets below. I prefer the second method but the first is easier to read later. I am looking for any speed improvements I can find as this is part of a large script. if ($y = 1) setVar $y 2 setVar $x 1 else setVar $y 1 setVar $x 2 end --------- setVar $tmp $y setVar $y $x setVar $x $tmp --------- [Edit] Yeah, I know looking for millisecond improvements is a bit anal...... |
|
| Author: | Zentock [ Thu Feb 02, 2006 8:51 pm ] |
| Post subject: | |
I vote for #2 Also as for speed any thing that makes it a ms faster per command will in the long run with large scripts accumulate into significant gains. Either in lower time needed for the script to execute or faster response to triggers, or less time for others to react to what ur doing. SO run for the speed. But Darn im preaching to the choir here. |
|
| Author: | Traitor [ Fri Feb 03, 2006 2:48 am ] |
| Post subject: | |
Prom, Unless you are doing thousands of these tests, there isn't really a difference. gettime $starttime setvar $count 1 while ($count < 1000000) .......if ($y = 1) .............setVar $y 2 ............. setVar $x 1 .......else ............. setVar $y 1 ............. setVar $x 2 .......end .......add $count 1 end gettime $endtime echo ANSI_10 "*" $starttime " " $endtime "*" gettime $starttime setvar $count 1 while ($count < 1000000) .......setVar $tmp $y .......setVar $y $x .......setVar $x $tmp .......add $count 1 end gettime $endtime echo ANSI_10 "*" $starttime " " $endtime "*" halt The output from the test: Loading and compiling script: scripts\zztest.ts 5:36:25 PM 5:36:45 PM 5:36:45 PM 5:37:03 PM Script terminated: scripts\zztest.ts 1st way: 20 seconds. 2nd way: 18 seconds. That's for 1 MILLION loops. So that's like .002 of a millisecond difference. |
|
| Author: | Mantis [ Fri Feb 03, 2006 5:43 pm ] |
| Post subject: | |
You could also try: setVar $y 3-$y setVar $x 3-$y |
|
| Author: | Promethius [ Sat Feb 04, 2006 4:24 am ] |
| Post subject: | |
Thanks for the replies and the test script. I ran the test on my server and had results of 15, 12, and 20 seconds (included Mantis's version). Not a major difference in time when the 1M loops are considered but it is still a small improvement. I would like someone to try Mantis's idea in a test again. It seems like it should be faster than what my test indicated. |
|
| Author: | ElderProphet [ Sat Feb 04, 2006 4:49 am ] |
| Post subject: | |
Actually, Mantis' way would be better in combination with method 2: setVar $x $y setVar $y (3-$x) You can deduce from the times posted that this will take about 14 seconds / million iterations on your box, Promethius. So you almost have the speed of method 2, and almost have the readability of method 1. Alternately, you could try a static array lookup, like this: # Create this array once, at the beginning: setArray $inverse 2 setVar $inverse[1] 2 setVar $inverse[2] 1 # then iterate this: setVar $x $y setVar $y $inverse[$x] If anyone tests this, I'd love to hear the results. +EP+ |
|
| Author: | ElderProphet [ Sat Feb 04, 2006 4:56 am ] |
| Post subject: | |
I'm pretty sure that value is good Promethius, regarding Mantis' mathematical approach. There are a number of inefficiencies in TWX that would cause this slow down. |
|
| Author: | Promethius [ Sat Feb 04, 2006 7:37 pm ] |
| Post subject: | |
Again, thanks to everyone for their input. If nothing else, this has shown me that what appears to be the most efficient method is sometimes not and the only way to know is to test the code. I know the times that were posted are machine dependent but the relationship between the times (faster/slower) shouldn't change. |
|
| Author: | Traitor [ Mon Feb 06, 2006 5:39 pm ] |
| Post subject: | |
Graz, I would love to own http://www.grimytrader.com http://www.grimytrader.com is the best place for TW scripts on the net! I visit http://www.grimytrader.com every day. You never know when something really cool will get uploaded to http://www.grimytrader.com Thanks to http://www.grimytrader.com I have a really cool script library. Kudos to RammaR and Cherokee for getting http://www.grimytrader.com online. Come on everyone, lets all sing! OH... I love http://www.grimytrader.com I love http://www.grimytrader.com I love http://www.grimytrader.com -I can't hear you- I love http://www.grimytrader.com I love http://www.grimytrader.com -People in the back!- I love http://www.grimytrader.com YEAH! heh |
|
| Author: | Desert Fox [ Tue Feb 07, 2006 3:42 am ] |
| Post subject: | |
Speeking of Cherokee, I think his webpage is ofline for good. Tried to get there the other day and it's GONE. Sorry to see it go. Just want to say Thanks for all you did for trade wars CK. Was kind of hopeing you would of released a few more scripts befor you totaly left. But hey thats the way it goes sometimes. Sorry for getting your discussion off the subject Pro. |
|
| Page 1 of 1 | All times are UTC - 5 hours |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|