Sujet : Re: else ladders practice
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 26. Nov 2024, 14:31:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vi4iji$3f7a3$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
User-Agent : Mozilla Thunderbird
On 26/11/2024 12:29, Tim Rentsch wrote:
Bart <bc@freeuk.com> writes:
On 25/11/2024 18:49, Tim Rentsch wrote:
>
Bart <bc@freeuk.com> writes:
>
It's funny how nobody seems to care about the speed of compilers
(which can vary by 100:1), but for the generated programs, the 2:1
speedup you might get by optimising it is vital!
>
I think most people would rather take this path (these times
are actual measured times of a recently written program):
>
compile time: 1 second
program run time: ~7 hours
>
than this path (extrapolated using the ratios mentioned above):
>
compile time: 0.01 second
program run time: ~14 hours
>
I'm trying to think of some computationally intensive app that would
run non-stop for several hours without interaction.
The conclusion is the same whether the program run time
is 7 hours, 7 minutes, or 7 seconds.
Funny you should mention 7 seconds. If I'm working on single source file called sql.c for example, that's how long it takes for gcc to create an unoptimised executable:
c:\cx>tm gcc sql.c #250Kloc file
TM: 7.38
Testing it might only take a second:
c:\cx>type input
select 2+2;
c:\cx>sql <input
4
With a different compiler then the edit-run cycle can be a lot nippier:
c:\cx>tm cc sql
Compiling sql.c to sql.exe
TM: 0.27
If that is still onerous, I can try interpreting:
c:\cx>tm cc -i sql <input
Compiling sql.c to sql.(int)
4
TM: 0.19
So compiling to IL, then interpreting that IL (which is 40 times slower than native code), /and/ running my test, takes 1/5th of a second in all.
That's 40 times faster than the equivalent with gcc-O0 (despite the interpreted part being 40 times slower!):
c:\cx\tm test.bat
c:\cx>gcc sql.c -osql.exe && sql 0<input
4
TM: 7.74
And 200 times faster than gcc-O2 which everyone here seems to be recommending:
c:\cx>tm test.bat
c:\cx>gcc sql.c -O2 -osql.exe && sql 0<input
4
TM: 38.60
Some might advise not working with such a large single source module at all, but that is the task here. If trying to investigate why my cc product is failing, I might put in tracing statements into the source, and compile and run with both compilers to compare the outputs. For such a purpose, -O2 or -O3 is utterly pointless.