I study Java and became interested in the work of the sin ( cos ) method. I noticed that the speed of obtaining a sine by j varies depending on the argument of the function. If the angle is less than 0.785 ... happy, then it calculates quickly, and if the larger one, respectively, slowly.
Compared with C #, it turned out about the opposite:
Checked in milliseconds for 10 million sine calculations.
Why are the results?
Here is the result for java cosine / sine from 0 to 4 * pi:
public static void main(String[] args) { long a; for (double x = 0; x < 4 * Math.PI; x = x + 0.05) { a = System.currentTimeMillis(); for (int i = 0; i < 10000000; i++) { //Math.cos(x); Math.sin(x); } System.out.printf("%.6f, %d \n", x, (System.currentTimeMillis() - a)); } } Here is the result for the cosine / sine of C # from 0 to 4 * pi:
public static void Main(string[] args) { for (double x = 0; x < 4 * Math.PI; x = x + 0.05) { Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 10000000; i++) { Math.Cos(x); // Math.Sin(x); } sw.Stop(); Console.WriteLine(x +" - " +(sw.ElapsedMilliseconds).ToString()); } } 


currentTimeMillismethod work injava? Try to increase the number of calculations by an order of magnitude. Will this picture persist? - Monk