// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.Random;

public class MaxSpeed {
    public static double max1(double[] x) {
        double res = Double.MIN_VALUE;
        for(int i = 0; i < x.length; i++) {
            if(x[i] > res) res = x[i];
        }
        return res;
    }
    public static double max2(double[] x) {
        double res = Double.MIN_VALUE;
        for(int i = 0; i < x.length; i++) {
            res = Math.max(res, x[i]);
        }
        return res;
    }
    private static final int N = 100000;
    private static final int REP = 1000;
    private static Random rng = new Random();
    public static void main(String[] args) {
        double[] x = new double[N];
        for(int i = 0; i < x.length; i++) {
            x[i] = rng.nextDouble();
        }
        double x1 = 0;
        long t1 = System.currentTimeMillis();
        for(int j = 0; j < REP; j++) {
            x1 = max1(x);
        }
        long t2 = System.currentTimeMillis();
        System.out.println(x1 + " " + (t2 - t1));
        double x2 = 0;
        long t3 = System.currentTimeMillis();
        for(int j = 0; j < REP; j++) {
            x2 = max2(x);
        }
        long t4 = System.currentTimeMillis();
        System.out.println(x2 + " " + (t4 - t3));
    }
}
