Last active
October 20, 2015 06:06
-
-
Save khvorov/499cec0bb8556ac04a09 to your computer and use it in GitHub Desktop.
Simple test to see how 'noexcept' improves performance of that code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// noexcept | |
// $ g++ -Wall -pedantic -std=c++1y -O3 -march=native -DNOEXCEPT="noexcept" noexcept_move.cpp && ./a.out | |
// cap.: 10000000 | |
// 28 ms | |
// no noexcept | |
// $ g++ -Wall -pedantic -std=c++1y -O3 -march=native -DNOEXCEPT="" noexcept_move.cpp && ./a.out | |
// cap.: 10000000 | |
// 251 ms | |
#include <chrono> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
using namespace std::chrono; | |
class X | |
{ | |
private: | |
string s; | |
public: | |
X() : s(100, 'a') {} | |
X(const X &x) = default; | |
X (X &&x) NOEXCEPT : s(move(x.s)) {} | |
}; | |
int main() | |
{ | |
vector<X> v(10000000); | |
cout << "cap.: " << v.capacity() << endl; | |
auto t0 = high_resolution_clock::now(); | |
v.emplace_back(); | |
auto t1 = high_resolution_clock::now(); | |
auto d = duration_cast<milliseconds>(t1 - t0); | |
cout << d.count() << " ms\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment