www.digitalmars.com         C & C++   DMDScript  

D - [Performance] Slowdown with -O Switch, Comparing to C

reply Manfred Nowak <svv1999 hotmail.com> writes:
I timed one of my little programs with and without optimization. With 
optimization turned on, it needed about 4% more time. Also turning on 
the release-switch gave the same time loss. Optimization and release 
switches both turned on, still gave a time loss of about .5%.

I checked two D-programs with its corresponding c-programs and noticed 
more then a 2.7-fold of the time the corresponding c-programs.

Are there similar observations?

So long.
Jan 28 2004
next sibling parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
How can we sensibly comment without seeing the code, and your
makefile/build-script?

"Manfred Nowak" <svv1999 hotmail.com> wrote in message
news:bvaaed$d57$1 digitaldaemon.com...
 I timed one of my little programs with and without optimization. With
 optimization turned on, it needed about 4% more time. Also turning on
 the release-switch gave the same time loss. Optimization and release
 switches both turned on, still gave a time loss of about .5%.

 I checked two D-programs with its corresponding c-programs and noticed
 more then a 2.7-fold of the time the corresponding c-programs.

 Are there similar observations?

 So long.

Jan 28 2004
parent Manfred Nowak <svv1999 hotmail.com> writes:
Matthew wrote:

 How can we sensibly comment without seeing the code, and your
 makefile/build-script?

Although I only asked for similar observations, the code and the reproduced outputs are posted or attached: Using WIN98SE, dmd 0.79. <editedProtocol> $ time normal real 0m9.990s real 0m10.000s real 0m9.990s $ time optim real 0m10.440s real 0m10.440s real 0m10.440s $ time release real 0m10.500s real 0m10.490s real 0m10.490s $ time optrel real 0m10.160s real 0m10.160s real 0m10.110s $ time awka_out real 0m3.680s real 0m3.680s real 0m3.680s </editProtocol> Here `normal' is compiled as `dmd test'. `optim' is compiled as `dmd -O test'. `release' is compiled as `dmd -release test'. `optrel' is compiled as `dmd -release -O test'. The resulting `test.exe' is then renamed to yield `normal.exe', `optim.exe', `release.exe' and `optrel.exe'. `awka_out' is compiled from the output of `awka -f test.awk' from http://awka.sourceforge.net using `gcc -o' under `cygwin'. The resulting program is attached. The timing is taken under `msys' on a nearly empty machine: <processes> EXPLORER.EXE 4294870915 C:\WINDOWS\EXPLORER.EXE KERNEL32.DLL 4291760303 C:\WINDOWS\SYSTEM\KERNEL32.DLL MCL.EXE 4294153267 C:\PROGRAMME\MCL\MCL.EXE MSGSRV32 4294919939 C:\WINDOWS\SYSTEM\MSGSRV32.EXE PRCVIEW.EXE 4294734255 C:\PROGRAMME\BASIC\PRCVIEW.EXE RUNDLL32.EXE 4294796463 C:\WINDOWS\RUNDLL32.EXE RXVT.EXE 4294045391 C:\PROGRAMME\MSYS\1.0\BIN\RXVT.EXE SH.EXE 4220066783 C:\PROGRAMME\MSYS\1.0\BIN\SH.EXE SYSTRAY.EXE 4294823403 C:\WINDOWS\SYSTEM\SYSTRAY.EXE WINOLDAP 4294137699 C:\WINDOWS\SYSTEM\WINOA386.MOD </processes> The input `test.awk' for `awka' is from its test suite: <awkscript> BEGIN { Switch["123"] = " abc " Switch["82"] = " def " Switch["985"] = " ghi " Switch["20"] = " jkl " Switch["1098"] = " mno " Switch["3874"] = " pqr " Switch["272"] = " stu " Switch_R["123"] = " 123 " Switch_R["82"] = " 82 " Switch_R["985"] = " 985 " Switch_R["20"] = " 20 " Switch_R["1098"] = " 1098 " Switch_R["3874"] = " 3874 " Switch_R["272"] = " 272 " for (i=0; i<30000; i++) { s1 = s2 = s3 = " 123 82 985 20 1098 3874 272 " for (j in Switch) { # Manually doing a gsub while (match(s1, j)) s1 = substr(s1, 1, RSTART-1) Switch[j] substr(s1, RSTART+RLENGTH) # Use gsub gsub(j, Switch[j], s2) # gsub, and prevent RE recompile gsub(Switch_R[j], Switch[j], s3) } } } </awkscript> This script is converted to D: <Dcode> import std.regexp, std.stream; void main(){ struct Dyn{ char[][] keys; char[][char[]] ass; void add(char[] key, char[] val){ keys.length=keys.length+1; keys[keys.length-1]=key; ass[key]=val; } }; Dyn Switch, Switch_R; Switch.add("123", " abc "); Switch.add("82", " def "); Switch.add("985", " ghi "); Switch.add("20", " jkl "); Switch.add("1098", " mno "); Switch.add("3874", " pqr "); Switch.add("272", " stu "); Switch_R.add("123", " 123 "); Switch_R.add("82", " 82 "); Switch_R.add("985", " 985 "); Switch_R.add("20", " 20 "); Switch_R.add("1098", " 1098 "); Switch_R.add("3874", " 3874 "); Switch_R.add("272", " 272 "); for (int i=0; i<30000; i++) { const char[] DATA= " 123 82 985 20 1098 3874 272 "; char[] s1, s2, s3; s1 = s2 = s3 = DATA; for(int i=0; i<Switch.keys.length;i++) { char[] j= Switch.keys[i]; // Manually doing a gsub RegExp jr=new RegExp(j,null); while (jr.test(s1)){ s1 = jr.replace(s1,Switch.ass[j]); } // Use gsub // gsub(j, Switch[j], s2) jr=new RegExp(j,"g"); s2=jr.replace(s2,Switch.ass[j]); // gsub, and prevent RE recompile // gsub(Switch_R[j], Switch[j], s3) jr=new RegExp(Switch_R.ass[j],"g"); s3=jr.replace(s3,Switch.ass[j]); } } } </Dcode> Have I contributed all necessary information? So long.
Jan 30 2004
prev sibling parent "C" <dont respond.com> writes:
Post the code somewhere ?

C
"Manfred Nowak" <svv1999 hotmail.com> wrote in message
news:bvaaed$d57$1 digitaldaemon.com...
 I timed one of my little programs with and without optimization. With
 optimization turned on, it needed about 4% more time. Also turning on
 the release-switch gave the same time loss. Optimization and release
 switches both turned on, still gave a time loss of about .5%.

 I checked two D-programs with its corresponding c-programs and noticed
 more then a 2.7-fold of the time the corresponding c-programs.

 Are there similar observations?

 So long.

Jan 29 2004