简体   繁体   中英

How do I calculate or view the number of instructions generated when compiled?

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 (eg 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.

gcc -S source.c; wc -l source.s

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM