4

Hello everyone Merry Christmas I need an advice I have the following code:

    int main()
{
    int k=5000000;
    int p;
    int sum=0;

    for (p=0;p<k;p++)
    {
        sum+=p;
    }

    return 0;
}

When I assemble it I get

main:
    pushl   %ebp
    movl    %esp, %ebp
    subl    $16, %esp
    movl    $5000000, -4(%ebp)
    movl    $0, -12(%ebp)
    movl    $0, -8(%ebp)
    jmp .L2
.L3:
    movl    -8(%ebp), %eax
    addl    %eax, -12(%ebp)
    addl    $1, -8(%ebp)
.L2:
    movl    -8(%ebp), %eax
    cmpl    -4(%ebp), %eax
    jl  .L3
    movl    $0, %eax
    leave
    ret

If I run it through gprof I get that main executed the most, which is quite obvious! Yet I want to go a step further and be able to know if L2, or L3 executed the most. here it is obvious that L3 executed the most. yet is there some kind of profiler, emulator that can give me that data for an entire code?

Syntax_Error
  • 5,964
  • 15
  • 53
  • 73
  • possible duplicate of [x86 assembly instruction execution count](http://stackoverflow.com/questions/4530527/x86-assembly-instruction-execution-count) – Hans Passant Dec 26 '10 at 14:19
  • no not rly! in that post I wanted to know if an insns executes which is irrelevant to this post were I want to know the hot sub function! – Syntax_Error Dec 26 '10 at 19:37

1 Answers1

1

Well, if you don't mind low-tech, you can answer any such question either by single-stepping, or by this way. For the latter method, it doesn't matter how big or complicated your program is.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • I looked at the 2nd way which linked me to a forum yet I couldn't understand the method used. would you explain it briefly as I saw a huge conversation below it – Syntax_Error Dec 26 '10 at 21:59
  • @Syntax_Error: Here's a [more recent explanation](http://stackoverflow.com/questions/4468022/how-to-measure/4501805#4501805) that may be easier to understand. If you want to see a discussion of the statistical principle, [try this](http://stackoverflow.com/questions/4387895/if-profiler-is-not-the-answer-what-other-choices-do-we-have/4390868#4390868). – Mike Dunlavey Dec 27 '10 at 01:17