Sin & Cos

New releases and general discussions.

Post » Sun Jul 26, 2009 11:25 am

Hi,

Today I was wondering if Sin & Cos are calculated in real time, or there is a pre-calculated array\table with all Sin\Cos results.

If not, and if you can do it, there will be the maximum performance when computing Sin & Cos.
B
2
S
1
G
3
Posts: 193
Reputation: 1,486

Post » Sun Jul 26, 2009 12:16 pm

It's calculated in real time for maximum precision, because you usually lose some accuracy with lookup tables.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,498

Post » Sun Jul 26, 2009 12:21 pm

Yeah, sin and cos usually are calculated for floats. I'd love to see a lookup table that contains all floats between 0 and 360 :lol:
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Mon Jul 27, 2009 10:18 pm

Yeah, it'll be faster for those who don't care of too much precision.
B
2
S
1
G
3
Posts: 193
Reputation: 1,486

Post » Tue Jul 28, 2009 4:37 am

If you want precalculated you could do a lookup within Construct, with an array
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Tue Jul 28, 2009 4:39 pm

[quote="Madster":6ic87a4j]If you want precalculated you could do a lookup within Construct, with an array[/quote:6ic87a4j]
That'd be much slower due to the overhead of running events. A sin or cos call can usually complete in under 200 cycles, which is about the overhead of running an event that calls an action that does nothing (let alone computing sin or cos).

[quote="Genesys":6ic87a4j]Yeah, it'll be faster for those who don't care of too much precision.[/quote:6ic87a4j]
Actually I doubt there will be any performance gains at all. Since performance improvements in 0.99, sin and cos don't appear as significant CPU users in profiles of the runtime, therefore there is little (read: none) gain to be had from further optimisation here.

Did anyone notice performance improvements in 0.99? They substantially improved the runtime performance, and I don't think anyone mentioned they saw a difference just yet, so I'm not sure anyone would actually notice even if I replaced sin and cos with approximations ;)
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,498

Post » Wed Jul 29, 2009 4:14 am

Uh forgot the event processing overhead (and should I assume there's some expression parsing overhead too?).
I'm still too used to C++ :P
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Wed Jul 29, 2009 5:14 pm

Yes, obviously expressions don't compute themselves magically out of thin air with no cost, but I think compared to running conditions the cost is small.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,498


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 5 guests