1 16 17 package org.apache.log4j.performance; 18 19 29 public class SystemTime { 30 31 static int RUN_LENGTH = 1000000; 32 33 static 34 public 35 void main(String [] args) { 36 double t = systemCurrentTimeLoop(); 37 System.out.println("Average System.currentTimeMillis() call took " + t); 38 39 t = currentThreadNameloop(); 40 System.out.println("Average Thread.currentThread().getName() call took " 41 + t); 42 43 } 44 45 static 46 double systemCurrentTimeLoop() { 47 long before = System.currentTimeMillis(); 48 long l; 49 for(int i = 0; i < RUN_LENGTH; i++) { 50 l = System.currentTimeMillis(); 51 } 52 return (System.currentTimeMillis() - before)*1000.0/RUN_LENGTH; 53 } 54 55 static 56 double currentThreadNameloop() { 57 long before = System.currentTimeMillis(); 58 String t; 59 for(int i = 0; i < RUN_LENGTH; i++) { 60 t = Thread.currentThread().getName(); 61 } 62 return (System.currentTimeMillis() - before)*1000.0/RUN_LENGTH; 63 } 64 } 65 | Popular Tags |