Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Odd benchmark behavior |
| Date | 2012-03-26 22:58 +1300 |
| Message-ID | <9tastcF3fiU9@mid.individual.net> (permalink) |
| References | <9talg3F84gU1@mid.individual.net> |
On 03/26/12 08:51 PM, Nils M Holm wrote:
> I ran across some odd (as far as I can tell) behavior recently, when
> performing some fun benchmarks. (Yeah, but please bear with me!)
>
> The goal was to find out how bad exactly the code generated by my
> toy compiler is, so I passed the following program to GNU C (GCC),
> Portable C (PCC), and my toy compiler (let's call it SCC):
>
> -----[ p.c ] ---------------------------------------------------
> #include<stdio.h>
>
> #define MAX 20000
>
> main() {
> int i, j, p[MAX], k;
>
> for (k=0, i=3; k<MAX; i+=2) {
> for (j=0; j<k; j++)
> if (i % p[j] == 0)
> break;
> if (j< k) continue;
> p[k++] = i;
> }
> printf("%d\n", p[k-1]);
> }
> ----------------------------------------------------------------
>
> Just a sieve algorithm to calculate the 20,000'th prime number,
> nothing fancy, just some tight loops. Please note that I do NOT
> intend to boast the code quality of SCC here. The code emitted by
> it is in fact abysmally bad. So I was quite surprised to get the
> following run times of the generated programs (median of three
> runs, almost no deviation):
>
> gcc -O2 p.c: 12.39s
> pcc -O p.c: 12.42s
> scc p.c: 12.27s
>
> I can explain the difference between GCC/PCC and SCC by lower
> startup overhead, but shouldn't the better code quality of PCC
> and GCC compensate for this over a run time of 12 seconds?
>
> I am rather puzzled now. Any ideas?
The probably isn't a great deal an optimiser can do with your code. I
tried your code (doubling to 40000 to get a meaningful time) and got a
run time between 3.3 and 3.4 seconds with everything from -g to -O3
(-fast with Sun cc),
--
Ian Collins
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Odd benchmark behavior Nils M Holm <news2009@t3x.org> - 2012-03-26 07:51 +0000
Re: Odd benchmark behavior "io_x" <a@b.c.invalid> - 2012-03-26 11:26 +0200
Re: Odd benchmark behavior "BartC" <bc@freeuk.com> - 2012-03-26 10:40 +0100
Re: Odd benchmark behavior gwowen <gwowen@gmail.com> - 2012-03-26 03:37 -0700
Re: Odd benchmark behavior "io_x" <a@b.c.invalid> - 2012-03-26 14:13 +0200
Re: Odd benchmark behavior "io_x" <a@b.c.invalid> - 2012-03-26 11:55 +0200
Re: Odd benchmark behavior "io_x" <a@b.c.invalid> - 2012-03-27 09:17 +0200
Re: Odd benchmark behavior "io_x" <a@b.c.invalid> - 2012-03-27 09:20 +0200
Re: Odd benchmark behavior "Scott Fluhrer" <sfluhrer@ix.netcom.com> - 2012-03-27 13:39 -0400
Re: Odd benchmark behavior pete <pfiland@mindspring.com> - 2012-03-27 21:49 -0500
Re: Odd benchmark behavior "io_x" <a@b.c.invalid> - 2012-04-05 12:18 +0200
Re: Odd benchmark behavior pete <pfiland@mindspring.com> - 2012-04-05 06:48 -0400
Re: Odd benchmark behavior "io_x" <a@b.c.invalid> - 2012-04-05 14:12 +0200
Re: Odd benchmark behavior pete <pfiland@mindspring.com> - 2012-04-05 09:03 -0400
Re: Odd benchmark behavior "io_x" <a@b.c.invalid> - 2012-04-05 16:18 +0200
Re: Odd benchmark behavior "io_x" <a@b.c.invalid> - 2012-04-07 13:26 +0200
Re: Odd benchmark behavior "io_x" <a@b.c.invalid> - 2012-04-06 09:31 +0200
Re: Odd benchmark behavior "io_x" <a@b.c.invalid> - 2012-03-27 19:01 +0200
Re: Odd benchmark behavior "BartC" <bc@freeuk.com> - 2012-03-26 10:36 +0100
Re: Odd benchmark behavior Nils M Holm <news2009@t3x.org> - 2012-03-26 10:02 +0000
Re: Odd benchmark behavior Ian Collins <ian-news@hotmail.com> - 2012-03-26 22:58 +1300
Re: Odd benchmark behavior "BartC" <bc@freeuk.com> - 2012-03-26 15:16 +0100
Re: Odd benchmark behavior Nils M Holm <news2009@t3x.org> - 2012-03-27 06:20 +0000
Re: Odd benchmark behavior "BartC" <bc@freeuk.com> - 2012-03-27 10:13 +0100
Re: Odd benchmark behavior Nils M Holm <news2009@t3x.org> - 2012-03-27 11:59 +0000
csiph-web