Jump to content

Amal

Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by Amal

  1. Hi. "How ever it might be, all benchmarks (and all threads about it on the web) clearly indicate that these days it is better to use Math.sin over any custom made version. Something often called: premature optimizations." (TrueBrain) It might not be the case if you use this: sourceforge.net/projects/jafama (has tables but they are small, so memory fetching might not be too large of an overhead) Remarks about MathHelper sin code: SIN_TABLE[(int)(par0 * 1024 / Math.PI / 2.0f) & 1023] 1) There are two divisions. Divisions are expensive, but here you can remove them. -> SIN_TABLE[(int)(par0 * 1024 * (1.0/(2*Math.PI))) & 1023] 2) Operations are done from left to right (if same priority), and you have a constant on the right, so you can add parentheses to end up with only one operation (HotSpot is smart enough to figure out constants). -> SIN_TABLE[(int)(par0 * (1024*(1.0/(2*Math.PI)))) & 1023] -> SIN_TABLE[(int)(par0 * (1024/(2.0*Math.PI))) & 1023] ->This should go way faster. 3) It would also be fine to only add parentheses since then the divisions will only occur once (also, 2.0f will be turned into a double, since it divides a double): -> SIN_TABLE[(int)(par0 * (1024 / Math.PI / 2.0f)) & 1023]
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.