哪个代码最快? [英] Which code is the fastest?

查看:108
本文介绍了哪个代码最快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!



哪个代码最快?



这一个:



Hello!

Which code is the fastest?

this one:

typedef struct tagDATA {
   int value;
} DATA, *LPDATA;

void foo(LPDATA data, int value) {
   doSomething(value);
}





或:





or:

typedef struct tagDATA {
   int value;
} DATA, *LPDATA;

void foo(LPDATA data) {
   doSomething(data->value);
}





感谢您的回答:)



我尝试了什么:



我已经实现了这两个代码,但我想知道方法是否比另一个快。



Thank you for any answer :)

What I have tried:

I have implemented these two codes but i want to know if a method is fastest than the other.

推荐答案

首先 - 为什么不运行自己的测试或使用某些工具???



两者之间没有可测量的差异,在这两种情况下都必须解析指向的指针,唯一的区别是在第一种情况下解析在函数外部完成(不在你的样本中)在第二种情况下它是在函数内部完成的......

性能的唯一区别可能是由于在第一种情况下传递了不需要的参数(LPDATA数据)...将数据推送到堆栈可能会在某些情况下导致性能问题......
First of all - why not run tests of your own or using some tools???

There is no measurable difference between the two, in both cases the pointer to value has to be resolved, the only difference is that in the first case the resolving done outside the function (not in your sample) and in the second case it is done inside the function...
The only difference in performance can be caused by passing unneeded parameter (LPDATA data) in the first case...Pushing that data to the stack may cause a performance issues in some cases...


这篇关于哪个代码最快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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