I have a built-in function
string myFunction() { return ""; }
Compared with
string myFunction() { return string(); }
Does the victim have performance?
Tested it on the VC2012 release using std :: string and QString (although on QString they return different results: thanks to DaoWen). Both show that the second version is about 3 times faster than the first. Thanks to all your answers and comments. The tested code is attached below.
#include <iostream> #include <string> #include <ctime> using namespace std; inline string fa() { return ""; } inline string fb() { return string(); } int main() { int N = 500000000; { clock_t begin = clock(); for (int i = 0; i < N; ++i) fa(); clock_t end = clock(); double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC; cout << "fa: " << elapsed_secs << "s \n"; } { clock_t begin = clock(); for (int i = 0; i < N; ++i) fb(); clock_t end = clock(); double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC; cout << "fb: " << elapsed_secs << "s \n"; } return 0; }
c ++
user1899020
source share