just how slow is...
the C++ sin() and cos() functions? is it really worth trading off memory to make lookup tables?
Well, at least it used to be faster to make lookup tables but nowadays there''s really no need to precalc them since there is basically no change in speed.
-----------------------------
Yes, this is a very witty signature.
-----------------------------
Yes, this is a very witty signature.
-----------------------------Yes, this is a very witty signature.
It may actually still be a good idea to put them into a table, at least if you limit yourself to 256 entries so there won''t be any cache miss. If you can live with the not-so-good-precision go for it.
Yeah, and of course, you never know what kind of morons might be trying to run your programs on a Pentium 133, so you''d better be safe anyway
Free Speech, Free Sklyarov
Fight the unconstitutional DMCA.
Commander M
Free Speech, Free Sklyarov
Fight the unconstitutional DMCA.
Commander M
November 05, 2001 07:20 AM
> [just how slow is] the C++ sin() and cos() functions?
It depends ... on your compiler, compiler settings, processor, operating environment, etc.
> is it really worth trading off memory to make lookup tables?
This depends on the benefit to you. If you only call sin() and cos() a few times a frame it probably won''t make a difference. If you rely on them a lot then you may benefit from using lookup tables, but then a better optimisation may be to redudce your dependence on trigonometry, e.g. by using quaternions instead of angles to represent rotations.
The best way is to try it and see: there''s no general answer to a problem like this and the only way to discover what''s best for you is try it in your own code.
It depends ... on your compiler, compiler settings, processor, operating environment, etc.
> is it really worth trading off memory to make lookup tables?
This depends on the benefit to you. If you only call sin() and cos() a few times a frame it probably won''t make a difference. If you rely on them a lot then you may benefit from using lookup tables, but then a better optimisation may be to redudce your dependence on trigonometry, e.g. by using quaternions instead of angles to represent rotations.
The best way is to try it and see: there''s no general answer to a problem like this and the only way to discover what''s best for you is try it in your own code.
Well, I setup a program that calculated the sin of 1024 double values in an input table and put the results in an output table 1024 times. On a 450MHZ Pentium III I got about 3.2 million per second. On 1.3ghz Pentium 4 I got about 6.5 million per second. So I would think a starting point would be how many do you need to do per second? If you don''t know then you need to reevaluate your approach to performance.
Keys to success: Ability, ambition and opportunity.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement