// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class Int2String {
   private final static int N = 10000000;

   public String empty(int x) {
      return "*";
   }

   public String simple(int x) {
      return Integer.toString(x);
   }

   public String newobject(int x) {
      Integer tmp = new Integer(x);
      return tmp.toString();
   }

   public String add(int x) {
      return ("" + x);
   }
   public static void main(String[] args) {
      Int2String test = new Int2String();
      System.out.println("simple: " + test.simple(123));
      System.out.println("newobject: " + test.newobject(123));
      System.out.println("add: " + test.add(123));
      long t1 = System.currentTimeMillis();
      for (int i = 0; i < N; i++) {
         test.empty(i / 100);
      }
      long t2 = System.currentTimeMillis();
      long t3 = System.currentTimeMillis();
      for (int i = 0; i < N; i++) {
         test.simple(i / 100);
      }
      long t4 = System.currentTimeMillis();
      System.out.println("simple = " + (t4 - t3 - (t2 - t1)));
      long t5 = System.currentTimeMillis();
      for (int i = 0; i < N; i++) {
         test.newobject(i / 100);
      }
      long t6 = System.currentTimeMillis();
      System.out.println("newobject = " + (t6 - t5 - (t2 - t1)));
      long t7 = System.currentTimeMillis();
      for (int i = 0; i < N; i++) {
         test.add(i / 100);
      }
      long t8 = System.currentTimeMillis();
      System.out.println("add = " + (t8 - t7 - (t2 - t1)));
   }
}
