title: How to use modern CPU instructions in Delphi? (Java faster than Delphi?)
body: <p>A friend sent me a comparison between a recent version of Delphi and Java (source code available if you want it). Believe it or not (better believe it) Java is now significant faster than Delphi because Delphi compiler won't take advantage of modern CPU instructions! A big breakthrough for the 'slow' Java. </p>
  
  <p>My question is: How can we use modern CPU instructions in Delphi WITHOUT resorting to ASM?</p>
  
  <p>The <a href="http://fastcode.sourceforge.net/" rel="nofollow noreferrer">FastCode</a> project was a partial answer to the above question but it is now abandoned. There is any other project similar to FastCode? </p>
  
  <p>This is another article showing that <strong>Java and C# it is indeed MUCH faster than Delphi</strong>: 
  <a href="http://webandlife.blogspot.com/2011/12/c-performance-vs-delphi-performance.html" rel="nofollow noreferrer">http://webandlife.blogspot.com/2011/12/c-performance-vs-delphi-performance.html</a></p>
  
  <hr>
  
  <p><strong>JAVA</strong>  </p>
  
  <pre class="lang-java prettyprint-override"><code>import java.util.Date;
  
  public class j
  {
    public static void xxx(int n, int m)
    {
          double t;
          int i, j;
          double d, r;
          t = 0.0;
          for (j = 1; j &lt;= n; j++)
          {
            t = t / 1000.0;
            for (i = 1; i &lt;= m; i++)
            {
                  t = t + i / 999999.0;
                  d = t * t + i;
                  r = (t + d) / (200000.0 * (i + 1));
                  t = t - r;
            }
          }
          System.out.println(t);
    }
  
    public static void main(String [] args)
    {
          Date t1, t2;
  
          t1 = new Date();
          xxx(1, 999999999);
          t2 = new Date();
          System.out.println((t2.getTime() - t1.getTime())/1000);
          t1 = new Date();
          xxx(1, 999999999);
          t2 = new Date();
          System.out.println((t2.getTime() - t1.getTime())/1000);
    }
  }
  </code></pre>
  
  <p>25 sec</p>
  
  <p><strong>DELPHI</strong>  </p>
  
  <pre><code>program d;
  {$APPTYPE CONSOLE}
  uses
    System.SysUtils, System.DateUtils;
  var
    t1, t2: TDateTime;
  
  procedure xxx (n: integer; m: integer);
  var
    t: double;
    i, j: integer;
    d, r: double;
  begin
    t:= 0.0;
    for j:= 1 to n do
    begin
          t:= t / 1000.0;
          for i:= 1 to m do
          begin
            t:= t + i / 999999.0;
            d:= t * t + i;
            r:= (t + d) / (200000.0 * (i + 1));
            t:= t - r;
          end;
    end;
    writeln(t);
  end;
  
  begin
    t1:= Now;
    xxx(1, 999999999);
    t2:= Now;
    writeln(SecondsBetween(t2,t1));
  
    t1:= Now;
    xxx(1, 999999999);
    t2:= Now;
    writeln(SecondsBetween(t2,t1));
  end.
  </code></pre>
  
  <p>37 sec</p>
  
  <hr>
  
  <p>It seems Delphi is still at the bottom of the chain: <a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html" rel="nofollow noreferrer">http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html</a></p>
  
  <p>I wonder how Lazarus compares with Delphi from this point of view.</p>