Very interesting.

I made some small additions to Roquen's code to do a little micro-benchmark of the different Math.sin approximation methods referenced in this and other threads between zero and +Math.PI. Thanks to Roquen, Kai, theagentd and Riven for contributing their different fast sin methods.

Here are the micro-benchmark results:

1 2 3 4 5 6 7 8 9
| Math.sin nanos per operation: 92.64692352 original nanos per operation: 15.45626018 horner nanos per operation: 12.8026165 range nanos per operation: 9.38279252 newk nanos per operation: 9.22229814 sin_9 nanos per operation: 7.35209479 sin_theagentd_lookup nanos per operation: 9.73315193 sinHalf nanos per operation: 7.10601857 sinFull nanos per operation: 6.19737146 |

I have little confidence in my own benchmarking abilities, but I did notice that these results are similar to Riven's given here (

http://www.java-gaming.org/topics/are-sin-cos-lookup-tables-still-relevant-today-with-regards-to-performance/29853/msg/274983/view.html#msg274983). Riven's sinHalf and sinFull methods take about 7% of the time needed for the Math.sin function in his test and in mine here.

Riven's SinHalf lookup table method is the fastest. Roquen's interesting sin_9 method is only marginally slower but I suspect it has far greater accuracy. The speed of Roquen's newk method given it's level of accuracy is pretty incredible.

I wanted to include the error table that Roquen showed and include Riven's methods too, but I did something wrong with measuring the error of Riven's look up tables since it was negative, so I won't post that error output until I have time to investigate.

Here is the code that I threw together to do these benchmarks. Apologies for the poor organisation. You may have to run it with the -Xmx6000M VM option to avoid running out of memory or else change the line "int numTestValues = 100000000;" to something smaller.

http://www.java-gaming.org/?action=pastebin&id=1489A big thank you to Roquen, Kai, theagentd and Riven for their code.