// 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 Double2String {
   private final static int N = 10000000;

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

   public String simple(double x) {
      return Double.toString(x);
   }

   public String newobject(double x) {
      Double tmp = new Double(x);
      return tmp.toString();
   }

   public String add(double x) {
      return ("" + x);
   }
   public static void main(String[] args) {
      Double2String test = new Double2String();
      System.out.println("simple: " + test.simple(123.456));
      System.out.println("newobject: " + test.newobject(123.456));
      System.out.println("add: " + test.add(123.456));
      long t1 = System.currentTimeMillis();
      for (int i = 0; i < N; i++) {
         test.empty(i / 100.0);
      }
      long t2 = System.currentTimeMillis();
      long t3 = System.currentTimeMillis();
      for (int i = 0; i < N; i++) {
         test.simple(i / 100.0);
      }
      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.0);
      }
      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.0);
      }
      long t8 = System.currentTimeMillis();
      System.out.println("add = " + (t8 - t7 - (t2 - t1)));
   }
}
