How to use modern CPU instructions in Delphi? (Java faster than Delphi?) -


a friend sent me comparison between recent version of delphi , java (source code available if want it). believe or not (better believe it) java significant faster delphi because delphi compiler won't take advantage of modern cpu instructions! big breakthrough 'slow' java.

my question is: how can use modern cpu instructions in delphi without resorting asm?

the fastcode project partial answer above question abandoned. there other project similar fastcode?

this article showing java , c# indeed faster delphi: http://webandlife.blogspot.com/2011/12/c-performance-vs-delphi-performance.html


java

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;         (j = 1; j <= n; j++)         {           t = t / 1000.0;           (i = 1; <= m; i++)           {                 t = t + / 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);   } } 

25 sec

delphi

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;   j:= 1 n   begin         t:= t / 1000.0;         i:= 1 m         begin           t:= t + / 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. 

37 sec


it seems delphi still @ bottom of chain: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

i wonder how lazarus compares delphi point of view.

according code, slow 32 bit delphi compiler floating point arithmetic support, far optimized, , copy lot of content on/to fpu stack.

in respect floating point arithmetic, not java jitted code faster. modern javascript jit compilers can better delphi!

this blog article reference this, , provide asm-level explanation delphi slowness floating point:

enter image description here

but if use delphi compiler targeting win64 platform, emit not x87 sse2 opcodes, , faster. suspect comparable java jitted executable.

and, in respect java, delphi executable use much less memory jvm, here, delphi executables on track!

if want code faster, not use asm nor low-level optimization trick, change algorithm. order of magnitude faster compilation hints. dedicated process achieved inlined asm opcodes - take @ this great set of articles such low level hacks. not easy master, , usually, proper software profiling , adding cache best way performance!


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -