View Single Post
  #5  
Old 05-23-2010, 11:06 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Just a note on the @temp.some_array syntax... when @ casts the array to a string, it will do a loop internally. This means that the @ operation on an array will take longer as the size of the array gets bigger.


Given the arrays N and M, it will take N.size() operations, then M.size() operations to convert them both to strings.
Then, to actually compare the two strings, it will take min(StringN.length(), StringM.length()) operations at worst (if they aren't equal).

So, that method of checking equality actually takes more operations than a GS2 loop.


However, since it is the engine doing the conversion to a string and the string equality check, it will be faster than doing a loop in GS2 (probably).


The one case where a GS2 loop would be better is if the arrays are really big, but differ near the beginning. This would be faster because you could break the loop on the first inequality. Converting the array to a string wouldn't be able to do that, which could be deadly on a really big array.

Last edited by WhiteDragon; 05-23-2010 at 11:19 AM..
Reply With Quote