simgear/simgear
Florent Rougon 1310092c0c SGPath: enable move operations
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
}
2017-11-18 14:54:33 +01:00
..
bucket Rename the COMPARE, COMPARE_EP, COMPARE_EP2 and VERIFY test macros 2016-12-04 21:04:40 +01:00
bvh Ensure <simgear_config.h> is always included. 2017-03-28 09:36:53 +01:00
canvas Handle case where no tranform matrix exists. 2017-10-13 17:35:21 +01:00
debug Fix a warning 2017-08-12 22:34:52 +02:00
embedded_resources Rename the ResourceProxy class to EmbeddedResourceProxy 2017-10-07 16:36:49 +02:00
environment alternative terrain engine - SGMesh utilizing pagedLOD 2017-02-25 19:17:55 -05:00
ephemeris Ensure <simgear_config.h> is always included. 2017-03-28 09:36:53 +01:00
hla Add missing include <algorithm> for std::max() and std::min() 2017-11-16 16:00:14 +01:00
io Fix missing headers in simgear/io/DNSClient.cxx and simgear/props/props_test.cxx 2017-11-13 10:04:34 +01:00
magvar chance the WMM epic form 1 jan 2005 to 1 jan 2015 2015-09-02 10:37:01 +02:00
math Fix (hopefully) sim4_t class initialization problems 2017-04-27 14:54:21 +02:00
misc SGPath: enable move operations 2017-11-18 14:54:33 +01:00
nasal Fix wrong argument 2017-11-13 08:22:14 +01:00
package Fix thumbnail loading on Windows 2017-07-28 12:05:35 +01:00
props Fix missing headers in simgear/io/DNSClient.cxx and simgear/props/props_test.cxx 2017-11-13 10:04:34 +01:00
scene Fix error message in axis object animation 2017-11-12 17:07:29 +01:00
screen Remove jpeg-factory. 2014-01-27 09:19:11 +00:00
serial Ensure <simgear_config.h> is always included. 2017-03-28 09:36:53 +01:00
sound int16_t needs cstdint 2017-10-31 11:22:39 +01:00
structure Add missing include <algorithm> for std::max() 2017-11-16 00:42:22 +01:00
threads Lots of (mostly) doxygen fixes/cleanup. 2014-08-01 00:13:25 +02:00
timing Remove sgGMTime, no longer used. 2017-03-17 23:25:25 +00:00
xml Move IOStreams-related files to simgear/io/iostreams; rename zfstream.[ch]xx to gzfstream.[ch]xx 2017-02-12 21:18:52 +01:00
.gitignore Remove obsolete ignore pattern for automake generated headers. 2012-02-17 23:46:06 +01:00
CMakeLists.txt Link shared SimGearScene with libgdal when enabled 2017-06-15 04:58:03 +02:00
compiler.h Define SG_DEPRECATED, remove unused DEPRECATED. 2017-04-05 22:09:52 +09:00
constants.h Add STG verbs for building mesh integration. 2016-09-22 20:38:58 +01:00
sg_inlines.h Add simgear::noexceptSwap() to simgear/sg_inlines.h 2017-11-13 11:59:11 +01:00
simgear_config_cmake.h.in alternative terrain engine - SGMesh utilizing pagedLOD 2017-02-25 19:17:55 -05:00
version.h.in Fix rpmlint/Linux packager complaints 2012-05-05 00:30:16 +02:00