equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
24 |
24 |
25 /* |
25 /* |
26 * Micro-benchmark for Math.pow() and Math.exp() |
26 * Micro-benchmark for Math.pow() and Math.exp() |
27 */ |
27 */ |
28 |
28 |
29 import java.util.*; |
29 import com.oracle.java.testlibrary.Utils; |
|
30 import java.util.Random; |
30 |
31 |
31 public class Test7177917 { |
32 public class Test7177917 { |
32 |
33 |
33 static double d; |
34 static double d; |
34 |
35 |
35 static Random r = new Random(0); |
36 static final Random R = Utils.getRandomInstance(); |
36 |
37 |
37 static long m_pow(double[][] values) { |
38 static long m_pow(double[][] values) { |
38 double res = 0; |
39 double res = 0; |
39 long start = System.nanoTime(); |
40 long start = System.nanoTime(); |
40 for (int i = 0; i < values.length; i++) { |
41 for (int i = 0; i < values.length; i++) { |
57 } |
58 } |
58 |
59 |
59 static double[][] pow_values(int nb) { |
60 static double[][] pow_values(int nb) { |
60 double[][] res = new double[nb][2]; |
61 double[][] res = new double[nb][2]; |
61 for (int i = 0; i < nb; i++) { |
62 for (int i = 0; i < nb; i++) { |
62 double ylogx = (1 + (r.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin |
63 double ylogx = (1 + (R.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin |
63 double x = Math.abs(Double.longBitsToDouble(r.nextLong())); |
64 double x = Math.abs(Double.longBitsToDouble(R.nextLong())); |
64 while (x != x) { |
65 while (x != x) { |
65 x = Math.abs(Double.longBitsToDouble(r.nextLong())); |
66 x = Math.abs(Double.longBitsToDouble(R.nextLong())); |
66 } |
67 } |
67 double logx = Math.log(x) / Math.log(2); |
68 double logx = Math.log(x) / Math.log(2); |
68 double y = ylogx / logx; |
69 double y = ylogx / logx; |
69 |
70 |
70 res[i][0] = x; |
71 res[i][0] = x; |
74 } |
75 } |
75 |
76 |
76 static double[] exp_values(int nb) { |
77 static double[] exp_values(int nb) { |
77 double[] res = new double[nb]; |
78 double[] res = new double[nb]; |
78 for (int i = 0; i < nb; i++) { |
79 for (int i = 0; i < nb; i++) { |
79 double ylogx = (1 + (r.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin |
80 double ylogx = (1 + (R.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin |
80 double x = Math.E; |
81 double x = Math.E; |
81 double logx = Math.log(x) / Math.log(2); |
82 double logx = Math.log(x) / Math.log(2); |
82 double y = ylogx / logx; |
83 double y = ylogx / logx; |
83 res[i] = y; |
84 res[i] = y; |
84 } |
85 } |