The GCC compiler has a default command called size for this! Compile the program using the GCC compiler. Then you can get the file size!
gcc -Wall test.c size
This is for a normal C program! Since you did not specify any parameter, it accepts. /a.out as your default option!
If you need to apply some optimization, the code will look like this.
praveenvinny@ubuntu :~/Project/New$> gcc -Wall -o1 -fauto-inc-dec test.c -o Output praveenvinny@ubuntu :~/Project/New$> size output text data bss dec hex filename 1067 256 8 1331 533 output
Use the text section for code size. You can use data and bss if you want to also consider the global size of the data.
This will print the code size,
time -f "%e" -o Output.log ./a.out
will print the runtime in a log file called Output.log
source share