View unanswered posts | View active topics It is currently Wed Sep 30, 2020 9:26 am

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Processor power consumption for different functions?
Author Message

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
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

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 12877
Location: Here
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

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

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

Who is online

Users browsing this forum: No registered users

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

Search for:
 Jump to:  Select a forum ------------------ Cortex Command    Dev Log    Wiki    Game Discussion    Game and Licensing Support    Mod Making       Lua Scripting       Requests    Mod Releases       Older Mods    Scene Releases       Scene Making Planetoid Pioneers    Game Discussion    Pioneer Program Lounge Data Realms Off-Topic    Off Topic Chat       Gaming       Forum Games    Site Support & Feedback