有沒有辦法通過傳遞參數來測量函數花了多少時間?我的想法是衡量函數的本體和整個函數本身。這是正確的方法嗎?下面僞代碼:測量將參數傳遞給函數所需的時間
int main(){
int start = time.now();
// passing by value
int timeOfFunc = foo(vector<my_object> huge_vector, vector<my_object2> huge_vector2);
int end = time.now();
int timeSpentPassingArgs = (end - start) - timeOfFunc; // getting time it takes to pass the argument?
}
int foo(vector<my_object> huge_vector, vector<my_object2> huge_vector2)
{
int start = time.now();
// body of the foo function
int end = time.now();
return (end - start);
}
'foo(vector huge_vector,vector huge_vector2)'這不是你如何調用函數。 –
Rakete1111
爲什麼你需要測量通過參數需要多長時間?如果你想要花費多長時間製作一份副本,只需要時間複印。否則,只需通過引用/ const引用/右值引用傳遞「大」對象,並且不要開始複製。 – NathanOliver
@ Rakete1111因此,短語「下面的僞代碼」 – WhozCraig