How to measure Code Size?

5.7k Views Asked by At

When certain features or optimizations are discussed, Code Size is often mentioned.

While I certainly understand the basic concept, that is, that a collection of code, compiled to machine code will result in X bytes of machine code (plus static data) I have recently realized that I'm very unsure how to actually measure Code Size of a given binary.

So, how do you measure Code Size?

Do you just check how big the resulting binary ("executable", .exe) is? Do you need a tool such as dumpbin.exe or some specific linker flags to get detailed results?

3

There are 3 best solutions below

5
On BEST ANSWER

You can tell the linker to produce a map file. This gives about the most detailed information that's easy to get (i.e., much short of reverse engineering the code by hand).

Depending on the code, using dumpbin on an object file can produce meaningful results, but can also produce simply "anonymous object" -- especially (exclusively?) when you ask for link-time code generation.

0
On

I'd say your best bet is to disassemble the binary.

In the context of code optimizations, total code size isn't typically what is meant, but rather code size for some specific part of your program.

0
On

If you mean .exe in bytes in the literal term I think you're over-thinking the question. Your file explorer should say on the right the size of files (if it doesn't, right click the file and open properties). The files you're looking for should be in debug named after .exe If it's something else, sorry.