Reputation: 713
I need to find the number of operations that a specific algorithm is doing: assigns, increments, comparators of integers, comparators of floats, multiplications of integers, etc.
I'm doing this manually and even though feasible it's a lot of work. So, do you know of any tool that does this automatically or semi-automatically?
I'm asking this because there are specific cases when I can't (or it's very difficult to) manually discover the number of operations. For example, the algorithm has one qsort
and looking at the confusing code of that function looks like a LOT of work.
Edit: In response to some comments on why do I want this. The objective in the future in to implement this algorithms that are currently on software in hardware language. So, as atan
latency differs from multiplications or sum latency, it is very important to measure which algorithm has the correct number of operations to be converted into hardware-language.
Upvotes: 2
Views: 1205
Reputation: 363980
You can use a profiler to get a statistical summary of how often each instruction runs, and/or how many clock cycles each one takes.
For your purpose of seeing the actual sequence of instructions run by a function, what you want is called a trace. That's the sequence of instructions that actually ran, in order, including branch instructions. The simplest way would be to set a breakpoint in gdb, then stepi
through the function you're interested in.
That's not viable for longer traces. There are automatic tools for doing this:
perf
: http://lwn.net/Articles/625957/Upvotes: 1
Reputation: 4306
Depending on what you mean by 'operations', one way to do this would be to compile the program and then use gdb to find the number of assembly instructions being run.
Upvotes: 1