Bay*_*kal 1 c++ pointers class
在我的程序中,我使用了几个类和大量的函数.我想知道哪一个可以更快地工作,或者它们之间在速度方面没有区别.
1st:Class功能
class mex{
public:
int length,nof_evaluations,nof_fast_evaluations;
tree T;
calc_mex(vector<string>,vector<double>);
};
Run Code Online (Sandbox Code Playgroud)
这将被称为
mex m;
vector<string> v1;
vector<double> v2;
m.calc_mex(v1,v2);
Run Code Online (Sandbox Code Playgroud)
2nd:具有类指针的函数
class mex{
public:
int length,nof_evaluations,nof_fast_evaluations;
tree T;
};
calc_mex(mex*,vector<string>,vector<double>);
Run Code Online (Sandbox Code Playgroud)
这将被称为
mex m,*mptr;
mptr=&m;
vector<string> v1;
vector<double> v2;
calc_mex(mptr,v1,v2);
Run Code Online (Sandbox Code Playgroud)
我正在使用我的程序中的两种方式,但更倾向于方式1,因为它看起来更干净,更有条理.我也在一次运行程序中调用这些类型的函数100K次.所以我想知道他们中的任何一个是否会更好地适应时间.
谢谢!
而不是加速决定因素应该是函数逻辑上是否属于类.如果是,请将其作为会员.如果没有使它成为一个独立的功能.
BTW每个成员函数都隐式传递一个this指针,因此两个版本之间没有太大区别.如果你真的关心性能.制作包含两个版本的示例程序,并在您的环境中使用大型数据集对其进行概要分析.