Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement