title: Java Double vs double: class type vs primitive type
body: <p>I was curious to what the performance differences between Java's class and primitive type for double were. So I created a little benchmark and found the class type to be 3x-7x slower than the primitive type. (3x on local machine OSX, 7x on ideone)</p>
  
  <p>Here is the test:</p>
  
  <pre><code>class Main {
      public static void main(String args[]) {
          long bigDTime, littleDTime;
  
          {
              long start = System.nanoTime();
              Double d = 0.0;
              for (Double i = 0.0; i &lt; 1432143.341; i += 0.1) {
                  d += i;
              }
              long end = System.nanoTime();
              bigDTime = end - start;
              System.out.println(bigDTime);
          }
  
          {
              long start = System.nanoTime();
              double d = 0.0;
              for (double i = 0.0; i &lt; 1432143.341; i += 0.1) {
                  d += i;
              }
              long end = System.nanoTime();
              littleDTime = end - start;
              System.out.println(littleDTime);
          }
  
          System.out.println("D/d = " + (bigDTime / littleDTime));
      }
  }
  </code></pre>
  
  <p><a href="http://ideone.com/fDizDu">http://ideone.com/fDizDu</a></p>
  
  <p>So why is the Double type so much slower? Why is it even implemented to allow mathematical operators?</p>