Advertisement
Guest User

Performance test

a guest
Feb 4th, 2010
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. import java.text.NumberFormat;
  2.  
  3. public class Main{
  4.  
  5.     public static void main(String[] args) {
  6.         long startTime = 0, endTime = 0;
  7.        
  8.         Child c = new Child();
  9.         Parent p = c;
  10.         Inter f = c;
  11.        
  12.         final long SIZE = 1000000000L;
  13.         NumberFormat format = NumberFormat.getInstance();
  14.        
  15.         startTime = System.nanoTime();
  16.         System.out.print("Direct refference => ");
  17.         for(int i=0; i<= SIZE; i++){
  18.             c.inc(i);
  19.         }
  20.         endTime = System.nanoTime();
  21.         System.out.println(format.format(endTime-startTime));
  22.  
  23.         startTime = System.nanoTime();
  24.         System.out.print("Parent refference => ");
  25.         for(int i=0; i<= SIZE; i++){
  26.             p.inc(i);
  27.         }
  28.         endTime = System.nanoTime();
  29.         System.out.println(format.format(endTime-startTime));
  30.    
  31.         startTime = System.nanoTime();
  32.         System.out.print("Interface refference => ");
  33.         for(int i=0; i<= SIZE; i++){
  34.             f.inc(i);
  35.         }
  36.         endTime = System.nanoTime();
  37.         System.out.println(format.format(endTime-startTime));  
  38.        
  39.  
  40.         startTime = System.nanoTime();
  41.         System.out.print("Static refference => ");
  42.         for(int i=0; i<= SIZE; i++){
  43.             Child.incS(i);
  44.         }
  45.         endTime = System.nanoTime();
  46.         System.out.println(format.format(endTime-startTime));  
  47.     }
  48. }
  49.  
  50. interface Inter {
  51.     public long inc(long l);
  52. }
  53.  
  54. class Child extends Parent implements Inter {
  55.     public long inc(long l){
  56.         return l+1;
  57.     }
  58.     public static long incS(long l){
  59.         return l+1;
  60.     }
  61. }
  62.  
  63. class Parent {
  64.     public long inc(long l){
  65.         return l+1;
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement