You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Enrico Migliore <en...@fatti.com> on 2005/10/17 09:12:12 UTC

C compilers comparison: MSVC vs GCC vs DevCpp

Hi,

    I did some tests  in order to see which, among MSVC,GCC and DevCpp
compilers yield the code with the best speed performance.

The test is a function that contains pure ANSI C code (no __fastcall or 
similar)
and doesn't call any system call of the underlying OS.


                            MSVC               GCC                   DevCpp
--------------------------------------------------------------------
Arch                    Pentium               Pentium                Pentium

OS                      Win2000            Linux (Knoppix)   Win2000

Compiler                 6.0                     3.4                     
   5.0
version

speed                  13.4 sec              14.27 sec            14.61 sec
optimization
off

speed                  6.48 sec               0.9 sec                
1.43 sec
optimization
on

command line     cl  /O2 main.c     gcc -O3 main.c        (*)
when optimiz.
on
--------------------------------------------------------------------

(*) I didn't write it down when I did the tests


Unless I'm doing something wrong with MSVC, it seems that
DevCpp and GCC are almost an order of magnitude faster than MSVC.


Enrico



Re: C compilers comparison: MSVC vs GCC vs DevCpp

Posted by Enrico Migliore <en...@fatti.com>.
Florian Weimer wrote:

>* Enrico Migliore:
>
>  
>
>>the code is a simple function that gets called 300000000 times.
>>    
>>
>
>There's an explicit check in GCC that prevents the removal of empty
>loops (because they are sometimes used for their timing effect on
>embedded targets, IIRC).  Therefore, your test is bogus.
>
>  
>
Hi Florian,

to make an exhaustive comparison of the various tool chains I'd need a 
test suite.
and yet, I never pretended that the test proposed was the one to use to 
select
a compiler rather than another.

I just wanted to see how the tested compilers build up the stack frame 
of function calls,
with and without optimization and the impact on the execution speed.

Enrico
  



Re: C compilers comparison: MSVC vs GCC vs DevCpp

Posted by Florian Weimer <fw...@deneb.enyo.de>.
* Enrico Migliore:

> the code is a simple function that gets called 300000000 times.

There's an explicit check in GCC that prevents the removal of empty
loops (because they are sometimes used for their timing effect on
embedded targets, IIRC).  Therefore, your test is bogus.

Re: C compilers comparison: MSVC vs GCC vs DevCpp

Posted by Enrico Migliore <en...@fatti.com>.
Tanuj Mathur wrote:

>Hi Enrico,
>  Could you provide a link to the code you used to perform these
>tests? i'd like to replicate the results for MSVC6, and then compare
>it with MSVC 7.1 and 8 (VS 2003 and VS 2005 Beta respectively). MSVC6
>is a very old compiler (1997/98), and since the C++ compiler for MSVC
>2003 (7.1) is available free of cost, that would be a way better
>compiler to target.
>
>Thanks,
>Tanuj
>
>  
>
Hi Tanuj,

 the code is a simple function that gets called 300000000 times.

-------------------------------------------------------------------------
#include <stdio.h>
#include <time.h>

int my_function (int a, char *buf)
{

   int  int_1 = 1987;
   char char_1 = 'a';
   long long_1 = 123456789L;
   long long_2 = &long_1;

   if (a > 0)
   {
       a++;
   }
   else
   {
       a--;
   }
   if (int_1 > 9)
   {
       char_1++;
   }
   else
   {
       char_1--;
   }
   *long_2++;
   if (buf == NULL)
   {
       return -1;
   }
   buf++;
   return a;
}


void main (void)
{

   long i;
   int result;
   char buf[8];
   clock_t start;
   clock_t stop;
   double  duration;

   buf[0] = 0;

   start = clock();
   for (i = 0; i < 300000000; i++)
   {
        result = my_function(10,buf);
   }
   stop = clock();
   duration = (double) (stop - start) / CLOCKS_PER_SEC;

   printf("the test lasted for %2.4f seconds\n\r",duration);
}
-------------------------------------------------------------------------

Enrico

Re: C compilers comparison: MSVC vs GCC vs DevCpp

Posted by Tanuj Mathur <ta...@gmail.com>.
Hi Enrico,
  Could you provide a link to the code you used to perform these
tests? i'd like to replicate the results for MSVC6, and then compare
it with MSVC 7.1 and 8 (VS 2003 and VS 2005 Beta respectively). MSVC6
is a very old compiler (1997/98), and since the C++ compiler for MSVC
2003 (7.1) is available free of cost, that would be a way better
compiler to target.

Thanks,
Tanuj

On 10/17/05, Enrico Migliore <en...@fatti.com> wrote:
> Hi,
>
>     I did some tests  in order to see which, among MSVC,GCC and DevCpp
> compilers yield the code with the best speed performance.
>
> The test is a function that contains pure ANSI C code (no __fastcall or
> similar)
> and doesn't call any system call of the underlying OS.
>
>
>                             MSVC               GCC                   DevCpp
> --------------------------------------------------------------------
> Arch                    Pentium               Pentium                Pentium
>
> OS                      Win2000            Linux (Knoppix)   Win2000
>
> Compiler                 6.0                     3.4
>    5.0
> version
>
> speed                  13.4 sec              14.27 sec            14.61 sec
> optimization
> off
>
> speed                  6.48 sec               0.9 sec
> 1.43 sec
> optimization
> on
>
> command line     cl  /O2 main.c     gcc -O3 main.c        (*)
> when optimiz.
> on
> --------------------------------------------------------------------
>
> (*) I didn't write it down when I did the tests
>
>
> Unless I'm doing something wrong with MSVC, it seems that
> DevCpp and GCC are almost an order of magnitude faster than MSVC.
>
>
> Enrico
>
>
>