Data Realms Fan Forums
http://45.55.195.193/

Processor power consumption for different functions?
http://45.55.195.193/viewtopic.php?f=73&t=30788
Page 1 of 1

Author:  ryry1237 [ Sat Mar 31, 2012 5:48 am ]
Post subject:  Processor power consumption for different functions?

Sorry about the somewhat vague title, title word limit won't let me say much else.

So I'm wondering if anyone here knows about how processor consumptive certain functions are compared to each other.

I'm pretty sure simpler calculations such as addition and subtraction take up much less power than say, finding the square root of pi, but to what scale exactly?

Does finding the square root of a value take a computer 10-20 times more processing power to figure out than something like finding the product between two numbers or is the value pretty much a negligible 2-3 times more processor consumptive?

Just kind of wondering since I'm thinking about how much processing power I can save if I were to do something like measure distance using an imperfect square area
Code:
if actor.Pos.X > self.Pos.X - 100 and actor.Pos.X < self.Pos.X + 100 and actor.Pos.Y > self.Pos.Y - 100 and actor.Pos.Y < self.Pos.Y + 100 then
<insert random code>

As opposed to a perfect spherical distance measuring function
Code:
   local curdist = math.sqrt(math.pow(self.Pos.X - actor.Pos.X) + math.pow(self.Pos.Y - actor.Pos.Y))
   if curdist < 100 then
<insert random code>


edit: also, do large numbers or numbers with many decimal places take longer to calculate? (e.g 1+1 vs 1.000001 + 1.000001)

Author:  CaveCricket48 [ Sat Mar 31, 2012 6:13 am ]
Post subject:  Re: Processor power consumption for different functions?

As far as I know, the rectangle area checks are faster than circular checks, and simpler numbers (1, 2, 3) are faster to perform calculations on that more complex numbers (100000, 1.0000001).

Author:  findude [ Sat Mar 31, 2012 3:13 pm ]
Post subject:  Re: Processor power consumption for different functions?

I think Lua considers all numbers double precision floats (ie. 0.00000000000 ) so there's nothing to be helped there.
Simpler math is always faster, though.

What's far more effective in optimizing the scripts is localizing your frequently used functions, such as those from math lib.

Code:
local random = math.random
function Update(self)
self.Vel = Vector(random(),random())
end


Here's some more stuff about Lua performance, not CC specific but still valid http://trac.caspring.org/wiki/LuaPerformance

Author:  ryry1237 [ Mon Apr 02, 2012 5:56 am ]
Post subject:  Re: Processor power consumption for different functions?

Good article.
Don't know quite enough about lua yet to figure out what everything means, but its helped a lot.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/