1310092c0c
This is done by simply not user-defining the copy constructor, copy-assignment operator and destructor. See [1] for more info. [1] http://accu.org/content/conf2014/Howard_Hinnant_Accu_2014.pdf For the benchmark below (compiled with the next commit to allow sorting SGPath instances), on Linux amd64 with g++ 6.3.0, I observe that enabling SGPath move operations with this commit increases the performance by 31% or 28% respectively, depending on whether I use this: // Typical code that creates a data structure in several steps and // benefits from move operations (the std::move() does nothing when // running the test with move operations disabled: a copy is made). auto p = SGPath::fromUtf8(randomString(0, 30)); v.emplace_back(std::move(p)); or that: v.emplace_back(randomString(0, 30)) for the initialization code. Now the benchmark code: using std::string; static std::default_random_engine randomNumbersGenerator; // Utility function: generate a random string whose length is in the // [minLen, maxLen] range. string randomString(string::size_type minLen, string::size_type maxLen) { std::uniform_int_distribution<string::size_type> sLenDist(minLen, maxLen); std::uniform_int_distribution<int> byteDist(0, 255); auto randomByte = std::bind(byteDist, randomNumbersGenerator); string::size_type len = sLenDist(randomNumbersGenerator); string str; while (str.size() < len) { str += std::char_traits<char>::to_char_type(randomByte()); } return str; } // The test function, run with nbIterations = 500000, minSize = 0 and // maxSize = 200 to obtain the figures given above. void SGPath_perfTest(std::size_t nbIterations, std::size_t minSize, std::size_t maxSize) { std::uniform_int_distribution<std::size_t> sizeDist(minSize, maxSize); auto randomSize = std::bind(sizeDist, randomNumbersGenerator); std::chrono::time_point<std::chrono::system_clock> start, end; start = std::chrono::system_clock::now(); vector<SGPath> v; for (std::size_t i=0; i < nbIterations; i++) { v = vector<SGPath>{}; // start anew for (std::size_t j=0; j < randomSize(); j++) { v.emplace_back(randomString(0, 30)); } std::shuffle(v.begin(), v.end(), randomNumbersGenerator); std::sort(v.begin(), v.end()); } end = std::chrono::system_clock::now(); std::chrono::duration<double> elapsedSecs = end - start; std::cout << elapsedSecs.count() << "\n"; // duration in seconds } |
||
---|---|---|
.. | ||
bucket | ||
bvh | ||
canvas | ||
debug | ||
embedded_resources | ||
environment | ||
ephemeris | ||
hla | ||
io | ||
magvar | ||
math | ||
misc | ||
nasal | ||
package | ||
props | ||
scene | ||
screen | ||
serial | ||
sound | ||
structure | ||
threads | ||
timing | ||
xml | ||
.gitignore | ||
CMakeLists.txt | ||
compiler.h | ||
constants.h | ||
sg_inlines.h | ||
simgear_config_cmake.h.in | ||
version.h.in |