是否有方法/函数可以获取使用 GCC 编译器编译的 C 程序的代码大小?(应用某些优化技术时可能会有所不同) [英] Is there a method/function to get the code size of a C program compiled using GCC compiler? (may vary when some optimization technique is applied)

查看:86
本文介绍了是否有方法/函数可以获取使用 GCC 编译器编译的 C 程序的代码大小?(应用某些优化技术时可能会有所不同)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我能否借助 fseek() 函数测量代码大小并将其存储到 shell 变量中?
  • 是否可以使用 milepost gccGNU Profiler 工具 提取代码大小、编译时间和执行时间?如果是,如何将它们存储到 shell 变量中?
  • Can I measure the code size with the help of an fseek() function and store it to a shell variable?
  • Is it possible to extract the code size, compilation time and execution time using milepost gcc or a GNU Profiler tool? If yes, how to store them into shell variables?

由于我的目标是在编译时间、执行时间和代码大小的基础上找到最佳优化技术,因此我期待一些可以返回这些参数的函数.

Since my aim is to find the best set of optimization technique upon the basis of the compilation time, execution time and code size, I will be expecting some function that can return these parameters.

MyPgm=/root/Project/Programs/test.c
gcc -Wall -o1 -fauto-inc-dec $MyPgm -o output
time -f "%e" -o Output.log ./output
while read line;
do
echo -e "$line";
Val=$line
done<Output.log

这会将执行时间存储到变量 Val 中.同样,我想获取代码大小和编译时间的值.我会更喜欢我可以做的事情来完成这项工作,而无需使用外部程序!

This will store the execution time to the variable Val. Similarly, I want to get the values of code size as well as compilation time. I will prefer something that I can do to accomplish this, without using an external program!

推荐答案

对于 linux 上的代码大小,您可以在终端上使用 size 命令.$size 文件名.out

for code size on linux, you can use size command on terminal. $size file-name.out

它将给出不同部分的大小.将文本部分用于代码大小.如果您还想考虑全局数据大小,您可以使用 data 和 bss.

it will give size of different sections. use text section for code size. you can use data and bss if you want to consider global data size as well.

这篇关于是否有方法/函数可以获取使用 GCC 编译器编译的 C 程序的代码大小?(应用某些优化技术时可能会有所不同)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆