Forum Topic: cost of Math functions

(184 views • 6 replies)

This topic is 1 page long.

<< < > >>
None

Disarray-yarrasiD

Reply To Post Reply & Quote

Posted at: 5/7/08 10:26 PM

Disarray-yarrasiD DARK LEVEL 09

Sign-Up: 11/14/04

Posts: 1,474

If someone could tell me the realitive cost of the following math functions it would be greatly appreciated:

+
-
*
/
Math.sqrt()
Math.pow()
Math.abs()

Thank you.

BBS Signature

None

Disarray-yarrasiD

Reply To Post Reply & Quote

Posted at: 5/7/08 10:34 PM

Disarray-yarrasiD DARK LEVEL 09

Sign-Up: 11/14/04

Posts: 1,474

At 5/7/08 10:26 PM, Disarray-yarrasiD wrote: If someone could tell me the realitive cost of the following math functions it would be greatly appreciated:

+
-
*
/
Math.sqrt()
Math.pow()
Math.abs()

Thank you.

Math.sin cos and tan are would be nice to know too.

BBS Signature

None

authorblues

Reply To Post Reply & Quote

Posted at: 5/7/08 10:46 PM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

At 5/7/08 10:26 PM, Disarray-yarrasiD wrote: +

atomic. single clock cycle.

-

atomic. single clock cycle.

*

minimal. several clock cycles.

/

minimal. several clock cycles.

Math.sqrt()

moderate. employs several arithmetic functions iteratively.
then its splined linearly.

Math.pow()

invokes Math.exp() and a few multiplications.
Math.exp() is about the same cost as Math.sqrt()

Math.abs()

minimal. a few conditionals.

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

authorblues

Reply To Post Reply & Quote

Posted at: 5/7/08 10:52 PM

authorblues FAB LEVEL 12

Sign-Up: 06/21/05

Posts: 6,360

At 5/7/08 10:34 PM, Disarray-yarrasiD wrote: Math.sin cos and tan are would be nice to know too.

those are just splined table-lookups. moderate.
range reduction algorithms can be costly, but modern compilers optimise the process significantly.

GENERATION 1-i: The first time you see this, copy it into your sig on any forum. Square it, and then add i to the generation.

BBS Signature

None

henke37

Reply To Post Reply & Quote

Posted at: 5/8/08 02:30 AM

henke37 NEUTRAL LEVEL 23

Sign-Up: 09/10/04

Posts: 3,607

I would not call division moderate, it's fairly slow. This also goes for modulous, %. Try to replace it with a multiply, or even better, a bit shift.

Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.


None

Disarray-yarrasiD

Reply To Post Reply & Quote

Posted at: 5/8/08 06:34 AM

Disarray-yarrasiD DARK LEVEL 09

Sign-Up: 11/14/04

Posts: 1,474

thank you very much

BBS Signature

None

thoughtpolice

Reply To Post Reply & Quote

Posted at: 5/8/08 06:35 AM

thoughtpolice DARK LEVEL 10

Sign-Up: 03/24/03

Posts: 3,101

At 5/8/08 02:30 AM, henke37 wrote: I would not call division moderate, it's fairly slow. This also goes for modulous, %. Try to replace it with a multiply, or even better, a bit shift.

Chances are, the JVM (or more specifically, HotSpot) is smart enough to do Strength reduction where appropriate to reduce overhead in cases like these. Nearly any modern compiler these days will. On that note, it might be worth examining.

omg.
Playstation Network tag: muffin-noodle
the empty set


All times are Eastern Standard Time (GMT -5) | Current Time: 10:58 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!