git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: {RFC/PATCH] micro-optimize get_sha1_hex()

From
Linus Torvalds <torvalds@osdl.org>
Date
Sep 10, 2006, 00:53 UTC
Message-ID
<Pine.LNX.4.64.0609091741420.27779@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.64.0609091639110.27779@g5.osdl.org>
On Sat, 9 Sep 2006, Linus Torvalds wrote:
>
> I _suspect_ that you profiled using "gprof" and the "-pg" flag to 
> the compiler?

Btw, in the absense of oprofile (which is very useful, and has the advantage that you can run many programs multiple times and get a "combined data" output from it all), what you can do (and which is more reliable) is:

 - the "minor pagefault" count that /usr/bin/time prints out is very 
   useful. It gives a pretty much direct view into what the total memory 
   use of the program was over its lifetime, in a way that very few other 
   things do.
 - using "gprof" to try to find _potential_ hotspots, but then not 
   trusting the profiling numbers at all for actual improvement, but 
   simply recompiling (witout profiling) and timing it for real after any 
   change. The real timings will almost certainly not match what you 
   thought you'd get from profiling, but now they'll be real numbers.
 - using "-pg" to link in the profiling code, BUT ONLY AT THE FINAL LINK 
   TIME! This will give you the "% time" and "cumulative seconds" part, 
   but it will mean that you will _not_ get the call-graph, because now 
   the actual code generation is not affected, and the compiler won't be 
   inserting all the call-graph-generation code. 

Note that the last use makes gprof much more accurate, but it also means that it won't _work_ very well for things that are fast. You usually have a 1/100th of a second profiling setup, so anything that is less than a second won't have much of a profile. So this only works for longer-running things.

		Linus
Previous: Linus Torvalds
Message 4 of 4 in “{RFC/PATCH] micro-optimize get_sha1_hex()”
  1. Junio C HamanoSep 9, 2006
  2. Jeff GarzikSep 9, 2006
  3. Linus TorvaldsSep 10, 2006
  4. Linus TorvaldsSep 10, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.