public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC Optimization Levels - Seeking Insights
@ 2023-12-21 19:32 Aran Nokan
  2023-12-21 19:57 ` Jonathan Wakely
  2023-12-24 13:54 ` Peter0x44
  0 siblings, 2 replies; 10+ messages in thread
From: Aran Nokan @ 2023-12-21 19:32 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1208 bytes --]

Hello GCC Community,

I recently conducted an experiment where I tested the impact of different
GCC optimization levels on the performance of a code
<https://github.com/leechwort/levenberg-maquardt-example>. I observed that
higher optimization levels didn't necessarily result in faster code
execution.

Is it correct or I have made a mistake? Do we have any other parameters for
optimization?


My make file was as follows:


CC=gcc
> CFLAGS_COMMON=-I.
> LDLAGS=-lm
> DEPS = levmarq.h
> OBJ = main.o levmarq.o
>
> %.o: %.c $(DEPS)
>         $(CC) -c -o $@ $< $(CFLAGS) $(LDLAGS)
>
> main: $(OBJ)
>         gcc -o $@ $^ $(CFLAGS) $(LDLAGS)
>
> # No optimization
> main_no_opt: CFLAGS += -O0
> main_no_opt: $(OBJ)
>         gcc -o $@ $^ $(CFLAGS) $(LDLAGS)
>
> # Basic optimization
> main_opt1: CFLAGS += -O1
> main_opt1: $(OBJ)
>         gcc -o $@ $^ $(CFLAGS) $(LDLAGS)
>
> # Moderate optimization
> main_opt2: CFLAGS += -O2
> main_opt2: $(OBJ)
>         gcc -o $@ $^ $(CFLAGS) $(LDLAGS)
>
> # High optimization
> main_opt3: CFLAGS += -O3
> main_opt3: $(OBJ)
>         gcc -o $@ $^ $(CFLAGS) $(LDLAGS)
>
> # Clean rule
> clean:
>         rm -f *.o main main_no_opt main_opt2 main_opt3
>

Best regards,
Aran

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-12-26 18:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-21 19:32 GCC Optimization Levels - Seeking Insights Aran Nokan
2023-12-21 19:57 ` Jonathan Wakely
2023-12-22  9:24   ` David Brown
2023-12-22 10:44     ` Aran Nokan
2023-12-22 11:25       ` David Brown
2023-12-22 11:51       ` Jonathan Wakely
2023-12-22 11:52         ` Jonathan Wakely
2023-12-25 16:21     ` NightStrike
2023-12-26 18:46       ` Segher Boessenkool
2023-12-24 13:54 ` Peter0x44

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).