Skip to content

Instantly share code, notes, and snippets.

@natemurthy
Last active August 29, 2015 14:20
Show Gist options
  • Save natemurthy/3b938a6241e1b762f3c5 to your computer and use it in GitHub Desktop.
Save natemurthy/3b938a6241e1b762f3c5 to your computer and use it in GitHub Desktop.
import java.util.*;
class JavaSample {
public static void main(String [] args) {
Random rand = new Random();
final int N = Integer.valueOf(args[0]);
List<Double> list = new ArrayList<Double>(N);
for (int i = 0; i < N; i++) {
list.add(rand.nextDouble());
}
long s = System.nanoTime();
double sum = 0;
for (double l : list) {
sum += l;
}
long e = System.nanoTime();
String time = String.valueOf((e-s)/1e9);
System.out.println("sum:" + String.valueOf(sum));
System.out.println("runtime: " + time);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment