Compiler made code run slower

Status
Not open for further replies.

H-Hour

Ars Scholae Palatinae
606
ok i got a question
i ran this program on a p4 1.8 Ghz @ 1.8 and got this output
Code:
FPUBench, V2.1

Module                 Error                  usec(iter)             MFLOPS
==============================================================================
df(x)/f(x)             4.0146e-013            0.0218                  641.6040
pi->atan(1.0)         -1.4166e-013            0.0183                  381.6014
I(0->pi/3)->sin(x)     4.7184e-014            0.0273                  623.1386
I(0->pi/3)->cos(x)     9.0594e-014            0.0117                 1283.2080
I(0->pi/3)->tan(x)    -6.2284e-014            0.0247                 1173.1985
I(x)->sin(x)*cos(x)    3.3640e-014            0.0211                 1375.1968
I(x)->x^2/(x^3+1)     -1.3074e-011            0.0601                  199.6037
I(x)->sin(x)*cos^2(x)  3.7692e-014            0.0221                 1355.9322

Summary:
========

   21 FADDs, 12 FSUBs, 14 FMULs, 5 FDIVs per iter =   436.9748 MFLOPS
   58 FADDs, 14 FSUBs, 66 FMULs, 14 FDIVs per iter =   437.9467 MFLOPS
   62 FADDs, 5 FSUBs, 74 FMULs, 5 FDIVs per iter =   773.1339 MFLOPS
   39 FADDs, 2 FSUBs, 50 FMULs, 0 FDIVs per iter =  1107.2770 MFLOPS

Press the any key to continue!

but when i downloaded the source and complied using .net i got this:

Code:
FPUBench, V2.1

Module                 Error                  usec(iter)             MFLOPS
==============================================================================
df(x)/f(x)             2.8422e-014            0.2151                   65.0879
pi->atan(1.0)          2.5047e-013            0.0845                   82.8632
I(0->pi/3)->sin(x)    -7.6605e-015            0.1901                   89.4406
I(0->pi/3)->cos(x)     2.2771e-013            0.0485                  309.5276
I(0->pi/3)->tan(x)     3.8858e-014            0.1209                  239.9638
I(x)->sin(x)*cos(x)    7.5495e-015            0.1144                  253.5346
I(x)->x^2/(x^3+1)     -1.1369e-013            0.0632                  189.7702
I(x)->sin(x)*cos^2(x)  1.2612e-013            0.1316                  227.9744

Summary:
========

   21 FADDs, 12 FSUBs, 14 FMULs, 5 FDIVs per iter =    84.9045 MFLOPS
   58 FADDs, 14 FSUBs, 66 FMULs, 14 FDIVs per iter =   161.3936 MFLOPS
   62 FADDs, 5 FSUBs, 74 FMULs, 5 FDIVs per iter =   165.2168 MFLOPS
   39 FADDs, 2 FSUBs, 50 FMULs, 0 FDIVs per iter =   187.8195 MFLOPS

Press the any key to continue!

im no programming wiz kid (2 semesters of C++, one of C) but is there a setting or something that im missing when i compile, or does the microsoft complier really that much slower than the intel complier

how can i get the x86 code from the .net complier too check
 
I wouldn't rely on your test for a measure of anything. Clearly, the code is not even remotely equivalent. Take a look at your "Error" field... it differs, sometimes significantly. Find something that at least gives you the same output, then get back to us. :)

On the other hand, the expectation is that .NET should be vastly slower than an Intel compiler generated stand-alone binary (for some operations). .NET should be slower than C++, too.
 

dhopton

Ars Tribunus Militum
2,009
The MS C compiler is designed for stability and good speed on all processors (from the pentium to the p4, from the k6 to the Athlon), hence it doesnt always generate the fastest code out there. Having said that, the intel compiler will generate code that sees not only a vast speed up on Intel CPU's, but also AMD :) try downloading the Intel compiler and see what your results are then.

When you say .net C compiler are you refering to the one in VS.net? Are you using the profressonal editon? The lesser versions dont include the full optimising compiler, so you'd not be seeing the relevant updates.
 
<stupid question>Did you compile with a debugging c library, or a production c library?</stupid question>

I don't know whether that'd matter, but last time I played with VC++ 5.0 (a while ago, as you can tell by the version number) the default behavior was to compile a debug, rather than release project. You had to switch some stuff to get rid of debug symbols, etc. This MIGHT contribute to some of that slowdown...
 

H-Hour

Ars Scholae Palatinae
606
and this is what i got

(this is on a 1.8 P4)

Downloaded .exe as is
Code:
FPUBench, V2.1

Module                 Error                  usec(iter)             MFLOPS
==============================================================================
df(x)/f(x)             4.0146e-013            0.0218                  641.6040
pi->atan(1.0)         -1.4166e-013            0.0183                  381.6014
I(0->pi/3)->sin(x)     4.7184e-014            0.0273                  623.1386
I(0->pi/3)->cos(x)     9.0594e-014            0.0117                 1283.2080
I(0->pi/3)->tan(x)    -6.2284e-014            0.0247                 1173.1985
I(x)->sin(x)*cos(x)    3.3640e-014            0.0211                 1375.1968
I(x)->x^2/(x^3+1)     -1.3074e-011            0.0601                  199.6037
I(x)->sin(x)*cos^2(x)  3.7692e-014            0.0221                 1355.9322

Summary:
========

   21 FADDs, 12 FSUBs, 14 FMULs, 5 FDIVs per iter =   436.9748 MFLOPS
   58 FADDs, 14 FSUBs, 66 FMULs, 14 FDIVs per iter =   437.9467 MFLOPS
   62 FADDs, 5 FSUBs, 74 FMULs, 5 FDIVs per iter =   773.1339 MFLOPS
   39 FADDs, 2 FSUBs, 50 FMULs, 0 FDIVs per iter =  1107.2770 MFLOPS

Press the any key to continue!


VSC++6 with complier set to "maximum speed"

Code:
FPUBench, V2.1

Module                 Error                  usec(iter)             MFLOPS
==============================================================================
df(x)/f(x)             4.0146e-013            0.0223                  626.7378
pi->atan(1.0)         -1.4166e-013            0.0217                  323.0575
I(0->pi/3)->sin(x)     4.7184e-014            0.0337                  504.1121
I(0->pi/3)->cos(x)    -1.2557e-013            0.0308                  487.6190
I(0->pi/3)->tan(x)    -1.3800e-013            0.0486                  596.9045
I(x)->sin(x)*cos(x)    3.2380e-013            0.0485                  598.4201
I(x)->x^2/(x^3+1)     -8.4583e-011            0.0657                  182.5529
I(x)->sin(x)*cos^2(x)  3.4867e-013            0.0531                  564.6436

Summary:
========

   21 FADDs, 12 FSUBs, 14 FMULs, 5 FDIVs per iter =   366.0361 MFLOPS
   58 FADDs, 14 FSUBs, 66 FMULs, 14 FDIVs per iter =   340.1934 MFLOPS
   62 FADDs, 5 FSUBs, 74 FMULs, 5 FDIVs per iter =   482.2741 MFLOPS
   39 FADDs, 2 FSUBs, 50 FMULs, 0 FDIVs per iter =   547.9413 MFLOPS

Press the any key to continue!

VSC++7 Acedemic complier set to "release"\

Code:
FPUBench, V2.1

Module                 Error                  usec(iter)             MFLOPS
==============================================================================
df(x)/f(x)             4.0146e-013            0.0319                  438.5707
pi->atan(1.0)         -1.4166e-013            0.0054                 1295.7339
I(0->pi/3)->sin(x)     4.7184e-014            0.0572                  297.2475
I(0->pi/3)->cos(x)    -1.2557e-013            0.0475                  316.1014
I(0->pi/3)->tan(x)    -1.3800e-013            0.0745                  389.2924
I(x)->sin(x)*cos(x)    3.2380e-013            0.0759                  382.2469
I(x)->x^2/(x^3+1)     -8.4583e-011            0.0652                  183.9191
I(x)->sin(x)*cos^2(x)  3.4867e-013            0.0715                  419.5690

Summary:
========

   21 FADDs, 12 FSUBs, 14 FMULs, 5 FDIVs per iter =   617.5543 MFLOPS
   58 FADDs, 14 FSUBs, 66 FMULs, 14 FDIVs per iter =   277.4168 MFLOPS
   62 FADDs, 5 FSUBs, 74 FMULs, 5 FDIVs per iter =   344.6031 MFLOPS
   39 FADDs, 2 FSUBs, 50 FMULs, 0 FDIVs per iter =   361.0915 MFLOPS

Press the any key to continue!

notice the second test -- there is quite an improvement (i ran the test twice just to be sure)
 

dereferenced

Ars Scholae Palatinae
706
One, IMO, annoying feature of the Intel compiler is that it embeds a copy of the switches used to compile a particular source file in its corresponding object file so that when linking you end up with a bunch of useless text strings clogging up your executable. This feature adds about 250kb to the executable of the Intel compiler itself! You can use the /Qsox- switch to turn this 'feature' off. The point being that even if they don't tell you, if you just look at the contents of the executable you may see what switches were used to compile it.

Why don't you tell us where this benchmark is available? Or is it not freely available?
 

H-Hour

Ars Scholae Palatinae
606
check out this thread
The Thread

this is were i got the binary -- the source is also there

this is the link Nebob posted in the same thread as above
Source

to get it to compile i had to declare a function prototype for dtime()
that is all the mods i made to the code.

Well, you're still getting different answers. Write your own test, then run the comparison!

i get different answers every time i run it with exception to the error data.

sorry -- i don't have the time to write code i want to write till after school is out :D

im just pointing out the differnces in the times the benchmark produced via different compliers

kinda curoius why compliers produce such different code at the machine level -- i know writing a compiler is very complex -- im working on a simple one for a class -- but is there that much diff in intel's vs. micorsoft's vs. borland's compliers?
 

John S

Ars Scholae Palatinae
1,464
Subscriptor
H-Hour, the Intel compiler is producing Pentium 4 specific code (using SSE2 instructions) which the MS compiler doesn't produce (since it wouldn't be portable amongst x86 platforms). Using these instructions, the P4 tends to perform quite well, sometimes significantly better than using plain x87 floating point instructions. The MS compiler can't hope to get that sort of performance out of the P4 unless it also uses the SSE2 instructions. And it doesn't hurt that the Intel compiler also puts out better x87 code.

So, yes, there is that big of a difference between the compilers. What might be more telling is MS vs. Borland (if you have their compiler) since both will use x87 code.

And of course you get different answers on different runs, that's why you should take an average of several runs. On one final note, the MS compiler is far more commonly used than the Intel compiler, so how close those numbers are to real world is, ATM, questionable; I don't think it would hurt most game developers (who produce most of the FP heavy programs the average person uses) to invest in a license for the Intel compiler to help out P4 users.
 
Status
Not open for further replies.