[Courses] C Programming For Absolute Beginners, Lesson 4: Getting Looped

Christopher Howard christopher.howard at frigidcode.com
Tue Mar 6 22:22:46 UTC 2012


On 03/06/2012 01:06 PM, Mel Chua wrote:
>> Note that this is an inefficient way to output this text. Less function
>> calls are generally more efficient than more function calls, because the
>> processor has to make larger jumps in the code, move parameters, and
>> such like. I/O calls are especially slow.
> 
> Out of curiosity, what (simple) tools are there to give rough gauges on
> how efficient your code is? Is there a gcc flag that will output some
> "efficiency" metric (and what efficiency metrics exist)?
> 
> The only thing I can come up with is "look at the timestamp when you
> start the compiler, and when the compilation finishes," and the same
> thing for when you run the actual program, but that's... a terrible,
> processor-dependent, other-processes-running-at-this-time-dependent,
> low-resolution data output way. There's got to be a better one.
> 
> --Mel
> _______________________________________________
> Courses mailing list
> Courses at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/courses

Most of what I know about efficiency is not from profiling but from
actually studying the architecture manuals, and seeing how code is
translated by GCC (or rather GAS) to the assembly level.

The manuals for amd64 at least are available at the following link,
which detail how the amd64 architecture works, and provide a lot of
useful information about optimization.

http://developer.amd.com/documentation/guides/Pages/default.aspx

Also, to see how your code gets translated into assembly language, just
run the following command on your C source code:

code:
----------
gcc -S mysourcecode.c
----------

Then open the file mysourcecode.s.

To answer your original question: probably the quickest way to do
profiling is with GNU profiler. It is part of binutils, so it should be
there if GCC is installed. This page gives an introductory explanation
of how to use it:

https://www.ibm.com/developerworks/library/l-gnuprof.html

-- 
frigidcode.com
indicium.us



More information about the Courses mailing list