AmbushedRaccoon

Move Semantics Performance test

Feb 20th, 2021
926
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <string>
  6. #include <chrono>
  7.  
  8. struct A
  9. {
  10.     A() = default;
  11.     A(const std::string& name) : _name(name) {}
  12.     A(const char* name) : _name(name) {}
  13.     A(const A& ref)
  14.     {
  15.         //std::cout << "A(const A& ref)" << std::endl;
  16.         _name = ref._name;
  17.     }
  18.     A& operator=(const A& ref)
  19.     {
  20.         //std::cout << "A& operator=(const A& ref)" << std::endl;
  21.         _name = ref._name;
  22.         return *this;
  23.     }
  24.     A(A&& ref) noexcept
  25.     {
  26.         //std::cout << "A(const A&& ref)" << std::endl;
  27.         _name = std::move(ref._name);
  28.     }
  29.     A& operator=(A&& ref) noexcept
  30.     {
  31.         //std::cout << "A& operator=( A&& ref)" << std::endl;
  32.         _name = std::move(ref._name);
  33.         return *this;
  34.     }
  35.  
  36.     std::string _name;
  37.  
  38. };
  39.  
  40. int main()
  41. {
  42.     std::vector<A> vec =
  43.     {
  44.         "k;jzxdxfjndfajk;bvmkl;adklm;dkl;m",
  45.         "pzSJD'kfsngv;adojgn;aojngear;on",
  46.         ";pksaMfkojnsg;'lkeng'eaoignea'oig",
  47.         "ckjhbnlxkjdhbnlkzdjbnklnjbjnbjnbjnjnnjbjnkxcbknxcbnjkxc",
  48.         "sdpfjgbosdjosidjgosigjdfiojsodijbsoijsoibijbjrjoiojbjbjiijrtijjrhjsjbisibjsijbjpsibsiojbosigbisobiosjbojisfg",
  49.         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  50.         "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
  51.         "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
  52.         "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
  53.         "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
  54.         "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
  55.         "vbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbsdddddddddddddddddddddddd",
  56.         "asdfasdfasdfasdfasdfsadfsadfsadfsadfsadfsadfasdfasdfasdfasdfasdfsdfasdfa",
  57.         "gdgdgdgdgdgdgdgdgdgdggdggdgdgdgdgduydgiuaysdfguasdyfguasdfuysadfgasduiyfgsafguysadfasugyf",
  58.         "gaegarefahfwaiefhaiuoyhfairufhaiufhaeifuhrefiarhfiuhfiuahfiuahgierugheiuheulihafuhvaiuvvvvvvvavavavver",
  59.         "k;jzxdxfjndfajk;bvmkl;adklm;dkl;m",
  60.         "pzSJD'kfsngv;adojgn;aojngear;on",
  61.         ";pksaMfkojnsg;'lkeng'eaoignea'oig",
  62.         "ckjhbnlxkjdhbnlkzdjbnklnjbjnbjnbjnjnnjbjnkxcbknxcbnjkxc",
  63.         "sdpfjgbosdjosidjgosigjdfiojsodijbsoijsoibijbjrjoiojbjbjiijrtijjrhjsjbisibjsijbjpsibsiojbosigbisobiosjbojisfg",
  64.         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  65.         "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
  66.         "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
  67.         "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
  68.         "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
  69.         "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
  70.         "vbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbsdddddddddddddddddddddddd",
  71.         "asdfasdfasdfasdfasdfsadfsadfsadfsadfsadfsadfasdfasdfasdfasdfasdfsdfasdfa",
  72.         "gdgdgdgdgdgdgdgdgdgdggdggdgdgdgdgduydgiuaysdfguasdyfguasdfuysadfgasduiyfgsafguysadfasugyf",
  73.         "gaegarefahfwaiefhaiuoyhfairufhaiufhaeifuhrefiarhfiuhfiuahfiuahgierugheiuheulihafuhvaiuvvvvvvvavavavver",
  74.         "k;jzxdxfjndfajk;bvmkl;adklm;dkl;m",
  75.         "pzSJD'kfsngv;adojgn;aojngear;on",
  76.         ";pksaMfkojnsg;'lkeng'eaoignea'oig",
  77.         "ckjhbnlxkjdhbnlkzdjbnklnjbjnbjnbjnjnnjbjnkxcbknxcbnjkxc",
  78.         "sdpfjgbosdjosidjgosigjdfiojsodijbsoijsoibijbjrjoiojbjbjiijrtijjrhjsjbisibjsijbjpsibsiojbosigbisobiosjbojisfg",
  79.         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  80.         "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
  81.         "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
  82.         "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
  83.         "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
  84.         "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
  85.         "vbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbsdddddddddddddddddddddddd",
  86.         "asdfasdfasdfasdfasdfsadfsadfsadfsadfsadfsadfasdfasdfasdfasdfasdfsdfasdfa",
  87.         "gdgdgdgdgdgdgdgdgdgdggdggdgdgdgdgduydgiuaysdfguasdyfguasdfuysadfgasduiyfgsafguysadfasugyf",
  88.         "gaegarefahfwaiefhaiuoyhfairufhaiufhaeifuhrefiarhfiuhfiuahfiuahgierugheiuheulihafuhvaiuvvvvvvvavavavver",
  89.         "k;jzxdxfjndfajk;bvmkl;adklm;dkl;m",
  90.         "pzSJD'kfsngv;adojgn;aojngear;on",
  91.         ";pksaMfkojnsg;'lkeng'eaoignea'oig",
  92.         "ckjhbnlxkjdhbnlkzdjbnklnjbjnbjnbjnjnnjbjnkxcbknxcbnjkxc",
  93.         "sdpfjgbosdjosidjgosigjdfiojsodijbsoijsoibijbjrjoiojbjbjiijrtijjrhjsjbisibjsijbjpsibsiojbosigbisobiosjbojisfg",
  94.         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  95.         "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
  96.         "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
  97.         "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
  98.         "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
  99.         "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
  100.         "vbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbsdddddddddddddddddddddddd",
  101.         "asdfasdfasdfasdfasdfsadfsadfsadfsadfsadfsadfasdfasdfasdfasdfasdfsdfasdfa",
  102.         "gdgdgdgdgdgdgdgdgdgdggdggdgdgdgdgduydgiuaysdfguasdyfguasdfuysadfgasduiyfgsafguysadfasugyf",
  103.         "gaegarefahfwaiefhaiuoyhfairufhaiufhaeifuhrefiarhfiuhfiuahfiuahgierugheiuheulihafuhvaiuvvvvvvvavavavver",
  104.     };
  105.  
  106.  
  107.     auto start_time = std::chrono::high_resolution_clock::now();
  108.     std::uint64_t count = 0;
  109.  
  110.     while (std::chrono::duration_cast<std::chrono::seconds>(std::chrono::high_resolution_clock::now() - start_time).count() < 60)
  111.     {
  112.         decltype(vec) tmp_vec = vec;
  113.         while (!tmp_vec.empty())
  114.         {
  115.             tmp_vec.erase(tmp_vec.begin());
  116.         }
  117.         count++;
  118.     }
  119.  
  120.     std::cout << count << std::endl;
  121.  
  122.     return 0;
  123. }
  124.  
  125.  
RAW Paste Data