Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 23rd, 2013  |  syntax: Java  |  size: 0.89 KB  |  views: 58  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class Tmp {
  2.     static double test(Runnable runnable) {
  3.         double start = System.currentTimeMillis();
  4.         runnable.run();
  5.         return (System.currentTimeMillis() - start) / 1000.0;
  6.     }
  7.  
  8.     public static void main(String[] args) {
  9.         final int n = 100000000;
  10.  
  11.         System.out.println(test(new Runnable() {
  12.                 public void run() {
  13.                     for(int i = 0; i < n; i++) {
  14.                         double x = Math.random();
  15.                         //System.out.println(x);
  16.                     }
  17.                 }
  18.             }));
  19.  
  20.         System.out.println(test(new Runnable() {
  21.                 public void run() {
  22.                     double x;
  23.                     for(int i = 0; i < n; i++) {
  24.                         x = Math.random();
  25.                         //System.out.println(x);
  26.                     }
  27.                 }}));
  28.     }
  29. }