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?
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?
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.