2

Basically, if I write a function I'd like to see that when it's compiled there are 15 instructions. Then I edit the function and see that there's now 20.

How can I measure this? Is there a tool? Do I need to learn some assembly?

NeomerArcana
  • 1,978
  • 3
  • 23
  • 50
  • I found this searching, not quite, but in the right direction; http://stackoverflow.com/questions/1020498/how-to-view-the-assembly-behind-the-code-using-visual-c – Evan Carslake Jan 04 '15 at 01:03

2 Answers2

3

The tool for viewing compiled code as assembly is called disassembler, but assembly output is built into most compiler suites. For gcc use gcc -S file.c command to view assembly output.

Many IDEs (e.g. Eclipse, NetBeans, Visual Studio) provide convenient windows to view such output.

You can also use online assembly viewers like http://gcc.godbolt.org/

Note that smaller number of instructions does not necessary mean that code is executing faster. Some instructions take longer time to execute than others, some may cause pipeline flush etc.

mip
  • 8,355
  • 6
  • 53
  • 72
1
gcc -S source.c; wc -l source.s
user14717
  • 4,757
  • 2
  • 44
  • 68