View unanswered posts | View active topics It is currently Thu Dec 26, 2024 3:55 pm



Reply to topic  [ 4 posts ] 
 Processor power consumption for different functions? 
Author Message
User avatar

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Reply with quote
Post 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)


Sat Mar 31, 2012 5:48 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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).


Sat Mar 31, 2012 6:13 am
Profile
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post 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


Sat Mar 31, 2012 3:13 pm
Profile
User avatar

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Reply with quote
Post 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.


Mon Apr 02, 2012 5:56 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.033s | 13 Queries | GZIP : Off ]