Calculus 30 Posted July 15, 2016 I'm always looking for ways to lower CPU usage on my scripts, and focus my coding practices mainly around this. I don't care if writing a method only takes up one line, if it uses 20% of your CPU, it's a bad method. Keeping that in mind, when you use the sleepUntil() method...it checks the condition you pass it in order. It would therefore make sense to do boolean checks which require the least amount of CPU power first, to make sure they have the chance of failing first before moving on to more CPU intensive activities... TLDR: Which method requires more CPU power: tile.equals(otherTile) OR string.equals(otherString) I don't have access to the tile.equals source code so I can't estimate on my own...
Eclipseop 194 Posted July 15, 2016 assuming dreambot does tile the same as every other bot, String#equals is more cpu intensive
Pandemic 2842 Posted July 15, 2016 String.equals is much slower, our tile.equals just compares x, y, and z.
Hopewelljnj 46 Posted July 15, 2016 You have to think about "the amount of" primitive data types it would require to do the same check. For instance a String with 1 character will takes less than one with 20. And comparing booleans ints longs are faster than most objects compares. And in the case of the string or tile the tile uses 3 int compares while the string uses a lot of characters.
Dreamlicker 750 Posted July 15, 2016 Assuming string.equals is comparing each character, string.equals is O(n) (where n is length of string) while tile.equals is O(1).
Hopewelljnj 46 Posted July 15, 2016 Assuming string.equals is comparing each character, string.equals is O(n) (where n is length of string) while tile.equals is O(1). Isn't it O(3) because x y z?
Cardozz 46 Posted July 15, 2016 Isn't it O(3) because x y z? Regular object he's talking about, not a Tile object Or one string with the xyz values in it
Pandemic 2842 Posted July 15, 2016 Isn't it O(3) because x y z? That's not how it works, it'd be O(1) because it's a constant time function regardless of input.
Hopewelljnj 46 Posted July 15, 2016 That's not how it works, it'd be O(1) because it's a constant time function regardless of input. Ah yes.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.