{"id":685,"date":"2020-02-13T23:10:16","date_gmt":"2020-02-13T14:10:16","guid":{"rendered":"http:\/\/hirlab.net\/nblog\/?p=685"},"modified":"2020-05-22T17:14:56","modified_gmt":"2020-05-22T08:14:56","slug":"c%e9%80%9f%e5%ba%a6%e5%ae%9f%e9%a8%93%ef%bc%9avector%e3%81%aepush_back%e3%81%a8emplace_back%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/","title":{"rendered":"\u3010\u901f\u5ea6\u5b9f\u9a13\u3011vector\u306epush_back()\u3068emplace_back()\u306f\u306a\u306b\u304c\u9055\u3046\u306e\u304b\uff1f"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_11 counter-hierarchy counter-decimal ez-toc-light-blue\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">\u30b3\u30f3\u30c6\u30f3\u30c4<\/p>\n<span class=\"ez-toc-title-toggle\"><a class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\"><i class=\"ez-toc-glyphicon ez-toc-icon-toggle\"><\/i><\/a><\/span><\/div>\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E3%81%AF%E3%81%98%E3%82%81%E3%81%AB\" title=\"\u306f\u3058\u3081\u306b\">\u306f\u3058\u3081\u306b<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#pushback()%E3%81%A8emplaceback()\" title=\"push_back()\u3068emplace_back()\">push_back()\u3068emplace_back()<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E3%82%B3%E3%83%94%E3%83%BC%E3%81%A8%E3%83%A0%E3%83%BC%E3%83%96\" title=\"\u30b3\u30d4\u30fc\u3068\u30e0\u30fc\u30d6\">\u30b3\u30d4\u30fc\u3068\u30e0\u30fc\u30d6<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E3%82%88%E3%81%8F%E3%81%82%E3%82%8B%E8%A9%B1\" title=\"\u3088\u304f\u3042\u308b\u8a71\">\u3088\u304f\u3042\u308b\u8a71<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E5%AE%9F%E9%A8%93%E6%9D%A1%E4%BB%B6\" title=\"\u5b9f\u9a13\u6761\u4ef6\">\u5b9f\u9a13\u6761\u4ef6<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E5%AE%9F%E9%A8%93%E3%83%9E%E3%82%B7%E3%83%B3%E3%82%B9%E3%83%9A%E3%83%83%E3%82%AF\" title=\"\u5b9f\u9a13\u30de\u30b7\u30f3\u30b9\u30da\u30c3\u30af\">\u5b9f\u9a13\u30de\u30b7\u30f3\u30b9\u30da\u30c3\u30af<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E8%A8%88%E6%B8%AC\" title=\"\u8a08\u6e2c\">\u8a08\u6e2c<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E6%8F%8F%E7%94%BB\" title=\"\u63cf\u753b\">\u63cf\u753b<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E5%AE%9F%E9%A8%931_double%E5%9E%8B\" title=\"\u5b9f\u9a131 : double\u578b\">\u5b9f\u9a131 : double\u578b<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E5%AE%9F%E9%A8%93%E7%B5%90%E6%9E%9C1\" title=\"\u5b9f\u9a13\u7d50\u679c1\">\u5b9f\u9a13\u7d50\u679c1<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E5%AE%9F%E9%A8%932_%E5%B0%8F%E3%81%95%E3%81%AA%E9%81%A9%E5%BD%93Class\" title=\"\u5b9f\u9a132 : \u5c0f\u3055\u306a\u9069\u5f53Class\">\u5b9f\u9a132 : \u5c0f\u3055\u306a\u9069\u5f53Class<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E5%AE%9F%E9%A8%93%E7%B5%90%E6%9E%9C2\" title=\"\u5b9f\u9a13\u7d50\u679c2\">\u5b9f\u9a13\u7d50\u679c2<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E5%AE%9F%E9%A8%933_%E3%82%B3%E3%83%94%E3%83%BC%E3%82%B3%E3%83%B3%E3%82%B9%E3%83%88%E3%83%A9%E3%82%AF%E3%82%BF%E3%81%8C%E9%87%8D%E3%82%81%E3%81%AE%E3%82%AF%E3%83%A9%E3%82%B9\" title=\"\u5b9f\u9a133 : \u30b3\u30d4\u30fc\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u304c\u91cd\u3081\u306e\u30af\u30e9\u30b9\">\u5b9f\u9a133 : \u30b3\u30d4\u30fc\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u304c\u91cd\u3081\u306e\u30af\u30e9\u30b9<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E5%AE%9F%E9%A8%93%E7%B5%90%E6%9E%9C3\" title=\"\u5b9f\u9a13\u7d50\u679c3\">\u5b9f\u9a13\u7d50\u679c3<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E8%A3%9C%E8%B6%B3\" title=\"\u88dc\u8db3\">\u88dc\u8db3<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E5%AE%9F%E9%A8%934_%E6%96%87%E5%AD%97%E5%88%97%E3%82%92%E8%A6%81%E7%B4%A0%E3%81%A8%E3%81%99%E3%82%8B%E5%A0%B4%E5%90%88\" title=\"\u5b9f\u9a134 : \u6587\u5b57\u5217\u3092\u8981\u7d20\u3068\u3059\u308b\u5834\u5408\">\u5b9f\u9a134 : \u6587\u5b57\u5217\u3092\u8981\u7d20\u3068\u3059\u308b\u5834\u5408<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E5%AE%9F%E9%A8%93%E7%B5%90%E6%9E%9C4\" title=\"\u5b9f\u9a13\u7d50\u679c4\">\u5b9f\u9a13\u7d50\u679c4<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E3%81%BE%E3%81%A8%E3%82%81\" title=\"\u307e\u3068\u3081\">\u307e\u3068\u3081<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#%E5%AE%9F%E9%A8%93%E3%81%AB%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%9F%E3%82%B3%E3%83%BC%E3%83%89\" title=\"\u5b9f\u9a13\u306b\u4f7f\u7528\u3057\u305f\u30b3\u30fc\u30c9\">\u5b9f\u9a13\u306b\u4f7f\u7528\u3057\u305f\u30b3\u30fc\u30c9<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#main_cpp\" title=\"main.cpp\">main.cpp<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_685\/#CMakeLists_txt\" title=\"CMakeLists.txt\">CMakeLists.txt<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"%E3%81%AF%E3%81%98%E3%82%81%E3%81%AB\"><\/span>\u306f\u3058\u3081\u306b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u4e45\u3057\u3076\u308a\u306e\u901f\u5ea6\u5b9f\u9a13\u3067\u3059\uff0e<\/p>\n<p>\u4eca\u56de\u3082\uff0cC++\u306evector\u306b\u3064\u3044\u3066\u306e\u8abf\u67fb\u5b9f\u9a13\u3067\u3059\uff0e<\/p>\n<p>\u524d\u56de\u306f\uff0cvector\u306e\u30e1\u30e2\u30ea\u78ba\u4fdd\u306b\u3064\u3044\u3066\u306e\u5b9f\u9a13\u3067\u3057\u305f\uff0e<\/p>\n<ol>\n<li>\u3010\u95a2\u9023\u8a18\u4e8b\u3011<a href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_316\/\" target=\"_blank\" rel=\"noopener noreferrer\">C++\u901f\u5ea6\u5b9f\u9a13\u305d\u306e\uff12\uff01vector\u914d\u5217\u306e\u6271\u3044\u306b\u3064\u3044\u3066<\/a><\/li>\n<\/ol>\n<p>\u3053\u308c\u304c\uff0c\u610f\u5916\u3068<mark>\u691c\u7d22\u7d50\u679c\u306e\u4e0a\u4f4d\u306b\u8868\u793a\u3055\u308c\u3066\u3044\u308b<\/mark>\u307f\u305f\u3044\u3067\uff0c\u591a\u304f\u306e\u65b9\u3005\u306b\u95b2\u89a7\u3055\u308c\u3066\u3044\u307e\u3059\uff0e<\/p>\n<p>\u7a1a\u62d9\u306a\u5185\u5bb9\u3068\u6587\u3067\uff0c\u6065\u305a\u304b\u3057\u3044\u601d\u3044\u3068\u5b09\u3057\u3044\u601d\u3044\u304c\u6df7\u3056\u3063\u3066\u3044\u307e\u3059\u304c\uff0c<mark>\u305d\u3093\u306a\u30ef\u30b1\u3067\u7d9a\u7de8\u3092\u3084\u308d\u3046\uff01<\/mark>\u3068\u306a\u308a\u307e\u3057\u305f\uff0e<\/p>\n<p>\u306a\u304a\uff0c\u672c\u8a18\u4e8b\u3067\u306f\u5c0f\u96e3\u3057\u3044\u8a71\u306f\u3057\u307e\u305b\u3093\uff0c\u3068\u3044\u3046\u304b\u66f8\u3044\u3066\u3044\u308b\u79c1\u304c\u307e\u3060\u6df1\u304f\u7406\u89e3\u3067\u304d\u3066\u3044\u306a\u3044\u306e\u3067\uff0c\u4e0b\u624b\u306a\u3053\u3068\u3092\u66f8\u304f\u3068\u8aa4\u89e3\u304c\u751f\u307e\u308c\u3061\u3083\u3046\u306e\u3067...<\/p>\n<h2><span class=\"ez-toc-section\" id=\"pushback()%E3%81%A8emplaceback()\"><\/span>push_back()\u3068emplace_back()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u3055\u3066\u672c\u984c\u3067\u3059\uff0e<\/p>\n<p>C++\u306evector\u30af\u30e9\u30b9\u306f\uff0cC++\u5229\u7528\u8005\u306b\u3068\u3063\u3066\u306f\u7121\u8996\u3067\u304d\u306a\u3044\u3068\u3066\u3082\u4fbf\u5229\u306a<mark><strong>\u30b3\u30f3\u30c6\u30ca\u30af\u30e9\u30b9<\/strong><\/mark>\u3067\u3059\uff0e<\/p>\n<p>\u4ed6\u306b\u3082\u914d\u5217\u3068\u3057\u3066\u6271\u3048\u308b\u30af\u30e9\u30b9\u306f\u3042\u308a\u307e\u3059\u304c\uff0c\u3068\u308a\u3042\u3048\u305a\u3053\u308c\u4f7f\u3063\u3068\u3051\u3063\u3066\u3044\u3046\u30af\u30e9\u30b9\u3067\u3059\uff0e<\/p>\n<p>\u304c\uff0c\u8981\u7d20\u3092\u683c\u7d0d\u3059\u308b\u95a2\u6570\u304c\uff12\u7a2e\u985e\u3042\u308a\u307e\u3059\uff0e<\/p>\n<p>\u305d\u3046\uff0c<strong>push_back()<\/strong>\u3068<strong>emplace_back()<\/strong>\u3067\u3059\uff0e<\/p>\n<p>emplace_back()\u306fC++11\u304b\u3089\u8ffd\u52a0\u3055\u308c\u305f\u95a2\u6570\u3067\u3059\uff0e<\/p>\n<p>\u7d50\u679c\u3068\u3057\u3066\u306f\uff0c\u540c\u3058\u300c\u8981\u7d20\u3092\u683c\u7d0d\u3059\u308b\u95a2\u6570\u300d\u306a\u306e\u3067\u3059\u304c\uff0c\u4f55\u304c\u9055\u3046\u306e\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E3%82%B3%E3%83%94%E3%83%BC%E3%81%A8%E3%83%A0%E3%83%BC%E3%83%96\"><\/span>\u30b3\u30d4\u30fc\u3068\u30e0\u30fc\u30d6<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u305d\u308c\u306f\uff0c\u8981\u7d20\u3092vector\u306b\u6e21\u3059\u3068\u304d\u306b\u751f\u3058\u307e\u3059\uff0e<\/p>\n<p>push_back()\u306e\u5834\u5408\uff0c\u5f15\u6570\u3068\u3057\u3066\u53d7\u3051\u53d6\u3063\u305f\u3082\u306e\u3092\u30b3\u30d4\u30fc\u3059\u308b\u305f\u3081\u306b<mark>\u4e00\u6642\u7684\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u751f\u6210\u304c\u306a\u3055\u308c\u308b<\/mark>\u3088\u3046\u3067\uff0c\u305d\u306e\u969b\u305d\u306e\u5f15\u6570\u306e<mark>\u30b3\u30d4\u30fc\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf<\/mark>\u3084<mark>\u30c7\u30b9\u30c8\u30e9\u30af\u30bf<\/mark>\u304c\u9010\u4e00\u547c\u3070\u308c\u308b\u3088\u3046\u3067\u3059\uff0e(\u3042\u3063\u3066\u308b\u306e\u304b\u306a)<\/p>\n<p>\u304c\uff0c\u305d\u308c\u306f\u7121\u99c4\u3068\u3044\u3046\u3053\u3068\u3067\uff0cemplace_back()\u304c\u767b\u5834\u3057\u307e\u3057\u305f\uff0e<\/p>\n<p>emplace_back()\u306f\uff0c\u5f15\u6570\u3068\u3057\u3066\u53d7\u3051\u53d6\u3063\u305f\u3082\u306e\u306e\u30af\u30e9\u30b9\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u5f15\u6570\u304b\u3089\uff0c\u76f4\u63a5\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30c8\u3059\u308b\u305f\u3081\u7121\u99c4\u304c\u306a\u3044\u3068\u304b\uff0e<\/p>\n<p>...\u3046\u30fc\u3093\uff0c\u3061\u3087\u3063\u3068\u8907\u96d1\uff0e<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E3%82%88%E3%81%8F%E3%81%82%E3%82%8B%E8%A9%B1\"><\/span>\u3088\u304f\u3042\u308b\u8a71<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>push_back()\u3068emplace_back()\u306e\u8a71\u984c\u306f\u7d50\u69cb\u3042\u3063\u3066\uff0c\u691c\u7d22\u3059\u308b\u3068\u305f\u304f\u3055\u3093\u51fa\u3066\u304d\u307e\u3059\uff0e<\/p>\n<p>\u305d\u3057\u3066\u7d50\u8ad6\u3068\u3057\u3066\uff0c\u300c<strong>\u3068\u308a\u3042\u3048\u305aemplace_back()\u3092\u4f7f\u3063\u3068\u3051<\/strong>\u300d\u3068\u306a\u3063\u3066\u3044\u308b\u8a18\u4e8b\u304c\u591a\u3044\u3067\u3059\u306d\uff0e<\/p>\n<p>\u305d\u308c\u3092\u4fe1\u3058\u3066\u79c1\u3082\u305d\u3046\u3057\u3066\u3044\u307e\u3057\u305f\u304c\uff0c<mark>\u3069\u306e\u7a0b\u5ea6\u901f\u304f\u306a\u308b\u306e\u304b<\/mark>\u306f\u6c17\u306b\u306a\u308a\u307e\u3059\u3088\u306d\uff0e<\/p>\n<p>\u305d\u308c\u3067\u306f\uff0c\u65e9\u901f\u5b9f\u9a13\u3057\u3066\u307f\u307e\u3057\u3087\u3046\uff0e<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E9%A8%93%E6%9D%A1%E4%BB%B6\"><\/span>\u5b9f\u9a13\u6761\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u307e\u305a\u306f\u5171\u901a\u306e\u5b9f\u9a13\u6761\u4ef6\u3067\u3059\uff0e<\/p>\n<p>\u30b3\u30fc\u30c9\u5168\u4f53\u306f\u6700\u5f8c\u306b\u8f09\u305b\u307e\u3059\u304c\uff0c\u5b9f\u9a13\u89e3\u8aac\u306e\u3068\u304d\u306b\u4f7f\u7528\u3059\u308b\u30b3\u30fc\u30c9\u306f\u305d\u306e\u4e00\u90e8\u306b\u306a\u308a\u307e\u3059\uff0e<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E9%A8%93%E3%83%9E%E3%82%B7%E3%83%B3%E3%82%B9%E3%83%9A%E3%83%83%E3%82%AF\"><\/span>\u5b9f\u9a13\u30de\u30b7\u30f3\u30b9\u30da\u30c3\u30af<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<table class=\"table\" style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 50%;\">OS<\/td>\n<td style=\"width: 50%;\">MacOS 10.15.3 (macbook pro 13 2018)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">CPU<\/td>\n<td style=\"width: 50%;\">Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz (4 cores)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 50%;\">RAM<\/td>\n<td style=\"width: 50%;\">16 GB<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><span class=\"ez-toc-section\" id=\"%E8%A8%88%E6%B8%AC\"><\/span>\u8a08\u6e2c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u6642\u9593\u306e\u8a08\u6e2c\u306fchrono\u3092\u4f7f\u7528\u3057\u3066\u30df\u30ea\u79d2\u5358\u4f4d\u3067\u8a08\u6e2c\u3057\u305f\u306e\u3061\uff0c\u79d2\u5358\u4f4d\u306b\u76f4\u3057\u3066\u89b3\u5bdf\u3057\u307e\u3059\uff0e<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E6%8F%8F%E7%94%BB\"><\/span>\u63cf\u753b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u4eca\u56de\u306f\u5b9f\u9a13\u7d50\u679c\u3092\u6bd4\u8f03\u3057\u3084\u3059\u3044\u3088\u3046\u306b\u30b0\u30e9\u30d5\u63cf\u753b\u3092\u884c\u3044\u307e\u3059\u304c\uff0c\u305d\u306e\u969b<mark><strong>matplotlibcpp<\/strong><\/mark>\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u307e\u3059\uff0e<\/p>\n<p>Python\u306e<mark>matplotlib\u3092C++\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u3066\u304f\u308c\u305f\u30d8\u30c3\u30c0\u30aa\u30f3\u30ea\u30e9\u30a4\u30d6\u30e9\u30ea<\/mark>\u3067\u3059\uff0e<\/p>\n<p>\u3061\u3087\u3063\u3068\u74b0\u5883\u69cb\u7bc9\u304c\u9762\u5012\u3067\u3059\u304cC++\u3067\u30b0\u30e9\u30d5\u63cf\u753b\u3059\u308b\u306a\u3089\uff0c\u4eca\u306e\u3068\u3053\u308d\u4e00\u756a\u4fbf\u5229\u304b\u306a\uff1f<\/p>\n<p>\u30bd\u30fc\u30b9\u306f\u4ee5\u4e0b\u306b\u8f09\u305b\u3066\u304a\u304d\u307e\u3059\uff0e<\/p>\n<p><a href=\"https:\/\/github.com\/lava\/matplotlib-cpp\" target=\"_blank\" rel=\"noopener noreferrer\">lava\/matplotlib-cpp: Extremely simple yet powerful header-only C++ plotting library built on the popular matplotlib<\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E9%A8%931_double%E5%9E%8B\"><\/span>\u5b9f\u9a131 : double\u578b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u307e\u305a\u306f64bit\u6d6e\u52d5\u5c0f\u6570\u70b9\u578b\u304b\u3089\uff0e<\/p>\n<pre class=\"lang:c++ decode:true \" title=\"C++_vector_\u901f\u5ea6\u5b9f\u9a13\">void expt1(int size){\r\n    vector&lt;double&gt; vec;\r\n    vec.reserve(size);\r\n    for(int i = 0; i &lt; size; ++i)\r\n        vec.emplace_back(0.1);\r\n}\r\n\r\nvoid expt2(int size){\r\n    vector&lt;double&gt; vec;\r\n    vec.reserve(size);\r\n    for(int i = 0; i &lt; size; ++i)\r\n        vec.push_back(0.1);\r\n}<\/pre>\n<p>\u3053\u306e\u4e8c\u3064\u3092\uff0c<mark>\u30b5\u30a4\u30ba1\u4e07~100\u4e07\u307e\u3067\u30921\u4e07\u523b\u307f<\/mark>\u3067\u4e0e\u3048\uff0c<mark>10\u8a66\u884c\u5e73\u5747<\/mark>\u3092\u89b3\u5bdf\u3057\u307e\u3059\uff0e<\/p>\n<p style=\"text-align: center;\">\u30b9\u30dd\u30f3\u30b5\u30fc\u30c9\u30ea\u30f3\u30af<\/p>\n<p><script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- article-mid --><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-7123758399787647\" data-ad-slot=\"2091992211\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E9%A8%93%E7%B5%90%E6%9E%9C1\"><\/span>\u5b9f\u9a13\u7d50\u679c1<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-687\" src=\"https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results.png\" alt=\"C++_vector_\u901f\u5ea6\u5b9f\u9a13\" width=\"640\" height=\"480\" srcset=\"https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results.png 640w, https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results-300x225.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>\u305d\u3093\u306a\u306b\u5dee\u306f\u51fa\u307e\u305b\u3093\u3067\u3057\u305f\u306d\uff0e<\/p>\n<p>push_back()\u306e\u65b9\u306f\uff0c\u5c0f\u3055\u306a\u30c7\u30fc\u30bf\u30b5\u30a4\u30ba\u3067\u304b\u306a\u308a\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3044\u307e\u3059\u304c\uff0c\u306a\u305c\u306a\u3093\u3067\u3057\u3087\u3046\u306d\uff1f<\/p>\n<p>\u3061\u3087\u3063\u3068\u308f\u304b\u308a\u307e\u305b\u3093\uff0c\u4f55\u304b\u3057\u3089\u306e\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u3067\u3057\u3087\u3046\u304b...<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E9%A8%932_%E5%B0%8F%E3%81%95%E3%81%AA%E9%81%A9%E5%BD%93Class\"><\/span>\u5b9f\u9a132 : \u5c0f\u3055\u306a\u9069\u5f53Class<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u6b21\u306f\u81ea\u5206\u3067\u4f5c\u3063\u305f\u9069\u5f53\u306a\u30af\u30e9\u30b9\u3092\u683c\u7d0d\u3057\u3066\u307f\u307e\u3059\uff0e<\/p>\n<p>\u4eca\u56de\u306f\u3053\u3093\u306a\u9069\u5f53\u30af\u30e9\u30b9\u3092\u7528\u610f\u3057\u3066\u307f\u307e\u3057\u305f\uff0e<\/p>\n<pre class=\"lang:c++ decode:true \" title=\"C++_vector_\u901f\u5ea6\u5b9f\u9a13\">class Sample{\r\nprivate:\r\n    double x, y;\r\npublic:\r\n    Sample(double x, double y): x(x), y(y){};\r\n    ~Sample(){};\r\n};<\/pre>\n<p>\u5c0f\u3055\u306a\u30af\u30e9\u30b9\u3067\u3059\u304c\uff0c\u3069\u3046\u306a\u308b\u3067\u3057\u3087\u3046\u304b\uff0e<\/p>\n<p>\u3042\uff0c\u3061\u306a\u307f\u306b\u30af\u30e9\u30b9\u3092\u683c\u7d0d\u3059\u308b\u3068\u304d\u306b\uff0c<span class=\"lang:c++ decode:true crayon-inline \">emplace_back(Sample(0.1, 0.1))<\/span>\u00a0\u3068\u3084\u3063\u305f\u3089push_back()\u3068\u540c\u3058\u3067\u3059\uff0e<\/p>\n<p><span class=\"lang:c++ decode:true crayon-inline \">emplace_back(0.1, 0.1)<\/span>\u00a0\u306e\u3088\u3046\u306b\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u5f15\u6570\u3092\u6e21\u3059\u3053\u3068\u3067emplace_back()\u306e\u826f\u3055\u304c\u51fa\u308b\u305d\u3046\uff0e<\/p>\n<p>\u3061\u306a\u307f\u306b\u30b5\u30a4\u30ba\u3084\u8a66\u884c\u56de\u6570\u306f\u5148\u307b\u3069\u3068\u540c\u3058\u3067\u3059\uff0e<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E9%A8%93%E7%B5%90%E6%9E%9C2\"><\/span>\u5b9f\u9a13\u7d50\u679c2<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-688\" src=\"https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results2.png\" alt=\"C++_vector_\u901f\u5ea6\u5b9f\u9a13\" width=\"640\" height=\"480\" srcset=\"https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results2.png 640w, https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results2-300x225.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>\u3084\u3084emplace_back()\u306e\u65b9\u304c\u901f\u3044...\u304b\u306a\uff1f<\/p>\n<p>\u5fae\u5999\u3067\u3059\u306d\uff0c\u305d\u3093\u306a\u306b\u5927\u304d\u306a\u5dee\u3067\u306f\u306a\u3055\u305d\u3046\u3067\u3059\uff0e(\u6709\u610f\u5dee\u306f\u9762\u5012\u306a\u306e\u3067\u8abf\u3079\u3066\u307e\u305b\u3093)<\/p>\n<p>\u307e\u3042\u305d\u308c\u3082\u305d\u306e\u306f\u305a\uff0c<mark><strong>\u5927\u4e8b\u306a\u306e\u306f\u30b3\u30d4\u30fc\u306e\u3068\u304d\u306b\u5927\u304d\u306a\u8a08\u7b97\u30b3\u30b9\u30c8\u304c\u304b\u304b\u308b\u304b\u3069\u3046\u304b<\/strong><\/mark>\uff0c\u3067\u3059\uff0e<\/p>\n<p>\u4eca\u56de\u306f\u30b3\u30d4\u30fc\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u7279\u306b\u5b9f\u88c5\u3057\u3066\u3044\u306a\u304b\u3063\u305f\u306e\u3067\uff0c\u3053\u306e\u3088\u3046\u306a\u7d50\u679c\u306b\u306a\u3063\u305f\u306e\u3057\u3087\u3046\uff0e<\/p>\n<p>(push_back()\u306e\u5c0f\u3055\u3044\u30b5\u30a4\u30ba\u3067\u306e\u4f4e\u901f\u73fe\u8c61\u306f\uff0c\u4f9d\u7136\u3068\u3057\u3066\u3042\u308a\u307e\u3059\u304c\uff0c\u3082\u3046\u7121\u8996\u3057\u307e\u3057\u3087\u3046)<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E9%A8%933_%E3%82%B3%E3%83%94%E3%83%BC%E3%82%B3%E3%83%B3%E3%82%B9%E3%83%88%E3%83%A9%E3%82%AF%E3%82%BF%E3%81%8C%E9%87%8D%E3%82%81%E3%81%AE%E3%82%AF%E3%83%A9%E3%82%B9\"><\/span>\u5b9f\u9a133 : \u30b3\u30d4\u30fc\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u304c\u91cd\u3081\u306e\u30af\u30e9\u30b9<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u3068\u3044\u3046\u30ef\u30b1\u3067\u5b9f\u88c5\u3057\u306a\u304a\u3057\u3066\u307f\u307e\u3057\u3087\u3046\uff0e<\/p>\n<p>\u30af\u30e9\u30b9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u6539\u5909\uff0e<\/p>\n<pre class=\"lang:c++ decode:true \" title=\"C++_vector_\u901f\u5ea6\u5b9f\u9a13\">class Sample{\r\nprivate:\r\n    double x, y;\r\npublic:\r\n    Sample(double x, double y): x(x), y(y) {};\r\n    \/\/ \u30b3\u30d4\u30fc\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\r\n    Sample(const Sample&amp;){ for(int i = 0; i &lt; 100; ++i){ \/*\u3061\u3087\u3063\u3068\u3057\u305f\u51e6\u7406*\/} };\r\n    ~Sample(){};\r\n};<\/pre>\n<p>\u3061\u3087\u3063\u3068\u30ef\u30b1\u3042\u3063\u3066\u8133\u7b4b\u306a\u5b9f\u88c5\u3060\u3051\u3069\uff0c\u3088\u3057\u3068\u3057\u307e\u3059\uff0e<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E9%A8%93%E7%B5%90%E6%9E%9C3\"><\/span>\u5b9f\u9a13\u7d50\u679c3<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-689\" src=\"https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results4.png\" alt=\"C++_vector_\u901f\u5ea6\u5b9f\u9a13\" width=\"640\" height=\"480\" srcset=\"https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results4.png 640w, https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results4-300x225.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>\u3053\u3053\u3067\u7d50\u69cb\u5dee\u304c\u51fa\u307e\u3057\u305f\uff0e<\/p>\n<p>\u3084\u306f\u308a\uff0c<mark><strong>push_back()\u3068emplace_back()\u306e\u5927\u304d\u306a\u5dee\u306f\u30b3\u30d4\u30fc<\/strong><\/mark>\u3067\u3059\u306d\uff0e<\/p>\n<p>\u3067\u3082\uff0c\u3053\u306e\u7d50\u679c\u304b\u3089\u5358\u7d14\u306bemplace_back()\u306e\u65b9\u304c\u512a\u308c\u3066\u3044\u308b\u3068\u7d50\u8ad6\u3065\u3051\u3066\u826f\u3044\u306e\u304b\u3069\u3046\u304b...<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E8%A3%9C%E8%B6%B3\"><\/span>\u88dc\u8db3<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u3061\u306a\u307f\u306b<span class=\"lang:c++ decode:true crayon-inline \">emplace_back(Sample(0.1, 0.1))<\/span>\u00a0\u3067\u5b9f\u9a13\u3059\u308b\u3068\uff0c\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3069\u3061\u3089\u3082\u30b3\u30d4\u30fc\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u304c\u547c\u3070\u308c\u3066\u3057\u307e\u3044\u5dee\u306f\u51fa\u307e\u305b\u3093\uff0e<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-691\" src=\"https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results3.png\" alt=\"C++_vector_\u901f\u5ea6\u5b9f\u9a13\" width=\"640\" height=\"480\" srcset=\"https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results3.png 640w, https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results3-300x225.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E9%A8%934_%E6%96%87%E5%AD%97%E5%88%97%E3%82%92%E8%A6%81%E7%B4%A0%E3%81%A8%E3%81%99%E3%82%8B%E5%A0%B4%E5%90%88\"><\/span>\u5b9f\u9a134 : \u6587\u5b57\u5217\u3092\u8981\u7d20\u3068\u3059\u308b\u5834\u5408<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u6700\u5f8c\u306f\u6587\u5b57\u5217(string)\u30af\u30e9\u30b9\u3067\u3084\u3063\u3066\u307f\u307e\u3059\uff0e<\/p>\n<pre class=\"lang:c++ decode:true\" title=\"C++_vector_string\">void expt1(int size){\r\n    vector&lt;string&gt; vec;\r\n    vec.reserve(size);\r\n    for(int i = 0; i &lt; size; ++i)\r\n        vec.emplace_back(\"sample text\");\r\n}\r\n\r\nvoid expt2(int size){\r\n    vector&lt;string&gt; vec;\r\n    vec.reserve(size);\r\n    for(int i = 0; i &lt; size; ++i)\r\n        vec.push_back(\"sample text\");\r\n}<\/pre>\n<p>\u306a\u305c\u306a\u3089\uff0c\u3088\u304f\u4f7f\u3046\u30af\u30e9\u30b9\u306e\u4e2d\u3067\u306f<mark>\u30b3\u30d4\u30fc\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u304c\u6bd4\u8f03\u7684\u91cd\u305d\u3046\u306a\u30af\u30e9\u30b9<\/mark>\u3060\u304b\u3089\uff0e<\/p>\n<p>\u3061\u306a\u307f\u306bstring\u306e\u30b3\u30d4\u30fc\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u306f\uff0c\u30e1\u30e2\u30ea\u9818\u57df\u78ba\u4fdd\u306b\u52a0\u3048\uff0cfor\u30eb\u30fc\u30d7\u306b\u3088\u308bchar\u914d\u5217\u30b3\u30d4\u30fc\u304c\u884c\u308f\u308c\u3066\u3044\u308b\u3088\u3046\u3067\u3059\uff0e<\/p>\n<p>(\u2193\u53c2\u8003: <a href=\"http:\/\/vivi.dyndns.org\/tech\/cpp\/str-construct-9.html\">C\/C++ \u30dd\u30a4\u30f3\u30bf\u5165\u9580 &gt; \u6587\u5b57\u5217\u30af\u30e9\u30b9 &gt; \u30b3\u30d4\u30fc\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf<\/a>)<\/p>\n<pre class=\"lang:c++ decode:true \" title=\"string_copy\">\/\/ string\u306e\u30b3\u30d4\u30fc\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\r\nString::String(const String &amp;x)\r\n    : m_allocSize(x.m_allocSize)  \/\/ \u30ad\u30e3\u30d1\u30b7\u30c6\u30a3\u3092\u521d\u671f\u5316\r\n    , m_data(new char[x.m_allocSize])    \/\/ \u6587\u5b57\u5217\u9818\u57df\u3092\u521d\u671f\u5316\r\n    , m_size(x.m_size)      \/\/ \u30b5\u30a4\u30ba\u3092\u521d\u671f\u5316\r\n{\r\n    for(int i = 0; i &lt;= m_size; ++i) {\r\n        m_data[i] = x.m_data[i];            \/\/ '\\0' \u307e\u3067\u6587\u5b57\u3092\u30b3\u30d4\u30fc\r\n    }\r\n}<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E9%A8%93%E7%B5%90%E6%9E%9C4\"><\/span>\u5b9f\u9a13\u7d50\u679c4<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-695\" src=\"https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results_str.png\" alt=\"c++_vector_string\" width=\"640\" height=\"480\" srcset=\"https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results_str.png 640w, https:\/\/hirlab.net\/nblog\/wp-content\/uploads\/2020\/02\/results_str-300x225.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>\u3084\u306f\u308a\u7d50\u679c\u306b\u5dee\u304c\u51fa\u307e\u3057\u305f\u306d\uff0e<\/p>\n<p>string\u3092\u683c\u7d0d\u3059\u308b\u306a\u3089\u3070emplace_back()\u306e\u65b9\u304c\u901f\u3044\u3067\u3059\uff0e<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E3%81%BE%E3%81%A8%E3%82%81\"><\/span>\u307e\u3068\u3081<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u4eca\u56de\u306fvector\u306epush_back()\u3068emplace_back()\u306e\u6bd4\u8f03\u5b9f\u9a13\u3092\u884c\u3044\u307e\u3057\u305f\uff0e<\/p>\n<p>\u7d50\u8ad6\u3068\u3057\u3066\u306f\u300c\u3068\u308a\u3042\u3048\u305aemplace_back()\u4f7f\u3063\u3068\u3051\u300d\u306f\u9593\u9055\u3063\u3066\u306f\u306a\u3055\u305d\u3046\u3067\u3059\uff0e<\/p>\n<p>\u7279\u306b<mark>\u30b3\u30d4\u30fc\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u304c\u91cd\u3081\u306e\u3082\u306e\u306femplace_back()\u304c\u529b\u3092\u767a\u63ee\u3057\u307e\u3059<\/mark>\uff0e<\/p>\n<p>\u305d\u308c\u3088\u308a\uff0c\u30c7\u30fc\u30bf\u30b5\u30a4\u30ba\u304c\u5c0f\u3055\u3044\u3068\u304d\u306bpush_back()\u304c\u9045\u3044\u306e\u306f\u306a\u305c\uff1f\uff1f<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E9%A8%93%E3%81%AB%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%9F%E3%82%B3%E3%83%BC%E3%83%89\"><\/span>\u5b9f\u9a13\u306b\u4f7f\u7528\u3057\u305f\u30b3\u30fc\u30c9<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"main_cpp\"><\/span>main.cpp<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre class=\"lang:c++ decode:true\" title=\"main.cpp\">\/**\r\n * C++\u901f\u5ea6\u5b9f\u9a13\uff1avector\u306epush_back()\u3068emplace_back()\u306b\u3064\u3044\u3066\r\n * \r\n * @author Hiroshi ARAKI\r\n * @copyright Hiroshi ARAKI\r\n * @date 2020.01.13\r\n *\/\r\n\r\n#include &lt;iostream&gt;\r\n#include &lt;vector&gt;\r\n#include &lt;chrono&gt;\r\n#include &lt;map&gt;\r\n#include &lt;string&gt;\r\n\r\n#include \"matplotlibcpp.h\"\r\n\r\n#define MINIMUM_SIZE 10000    \/\/ vector\u6700\u5c0f\u30b5\u30a4\u30ba\r\n#define MAXIMUM_SIZE 1000000  \/\/ vector\u6700\u5927\u30b5\u30a4\u30ba\r\n\r\n\r\nusing namespace std;\r\nnamespace plt = matplotlibcpp;\r\n\r\n\r\n\/**\r\n * \u30b5\u30f3\u30d7\u30eb\u30af\u30e9\u30b9\r\n *\/\r\nclass Sample{\r\nprivate:\r\n    double x, y;\r\npublic:\r\n    Sample(double x, double y): x(x), y(y) {};\r\n    \/\/ \u30b3\u30d4\u30fc\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\r\n    Sample(const Sample&amp;){ for(int i = 0; i &lt; 100; ++i){ \/*\u3061\u3087\u3063\u3068\u3057\u305f\u51e6\u7406*\/} };\r\n    ~Sample(){};\r\n};\r\n\r\n\/**\r\n * \u5b9f\u9a13\uff11\r\n * @param size\r\n *\/\r\nvoid expt1(int size){\r\n    vector&lt;Sample&gt; vec;\r\n    vec.reserve(size);\r\n    for(int i = 0; i &lt; size; ++i)\r\n        vec.emplace_back(Sample(0.1, 0.1));\r\n}\r\n\r\n\/**\r\n * \u5b9f\u9a13\uff12\r\n * @param size\r\n *\/\r\nvoid expt2(int size){\r\n    vector&lt;Sample&gt; vec;\r\n    vec.reserve(size);\r\n    for(int i = 0; i &lt; size; ++i)\r\n        vec.push_back(Sample(0.1, 0.1));\r\n}\r\n\r\nint main() {\r\n    int trial = 10;  \/\/ \u8a66\u884c\u56de\u6570\r\n\r\n    \/\/ \u63cf\u753b\u7528 (x-axis)\r\n    vector&lt;double&gt; x;\r\n    x.reserve(1000);\r\n    for(int s = MINIMUM_SIZE; s &lt;= MAXIMUM_SIZE; s += MINIMUM_SIZE)\r\n        x.emplace_back(s);\r\n\r\n    \/\/ \u7d50\u679c\u8a18\u9332\u7528\r\n    vector&lt;double&gt; results1(MAXIMUM_SIZE \/ MINIMUM_SIZE, 0);\r\n    vector&lt;double&gt; results2(MAXIMUM_SIZE \/ MINIMUM_SIZE, 0);\r\n\r\n    \/\/ \u6642\u9593\u8a18\u9332\u7528\r\n    chrono::system_clock::time_point start, end;\r\n\r\n    \/* \u5b9f\u9a13\uff11 *\/\r\n    for(int t = 0; t &lt; trial; ++t) {\r\n        cout &lt;&lt; \"Expt1: Trial \" &lt;&lt; t &lt;&lt; \"\/\" &lt;&lt; trial &lt;&lt; endl;\r\n        for(int s = MINIMUM_SIZE; s &lt;= MAXIMUM_SIZE; s += MINIMUM_SIZE){\r\n            start = chrono::system_clock::now();\r\n            expt1(s);\r\n            end = chrono::system_clock::now();\r\n            results1[s \/ MINIMUM_SIZE] += chrono::duration_cast&lt;chrono::milliseconds&gt;( end - start ).count() \/ 1000.0;\r\n        }\r\n    }\r\n\r\n\r\n    \/* \u5b9f\u9a13\uff12 *\/\r\n    for(int t = 0; t &lt; trial; ++t) {\r\n        cout &lt;&lt; \"Expt2: Trial \" &lt;&lt; t &lt;&lt; \"\/\" &lt;&lt; trial &lt;&lt; endl;\r\n        for(int s = MINIMUM_SIZE; s &lt;= MAXIMUM_SIZE; s += MINIMUM_SIZE){\r\n            start = chrono::system_clock::now();\r\n            expt2(s);\r\n            end = chrono::system_clock::now();\r\n            results2[s \/ MINIMUM_SIZE] += chrono::duration_cast&lt;chrono::milliseconds&gt;( end - start ).count() \/ 1000.0;\r\n        }\r\n    }\r\n\r\n    \/\/ 10\u8a66\u884c\u5e73\u5747\u6642\u9593\u306b\u3059\u308b\r\n    for(auto&amp; res: results1) {\r\n        res \/= static_cast&lt;double&gt;(trial);\r\n    }\r\n    for(auto&amp; res: results2) {\r\n        res \/= static_cast&lt;double&gt;(trial);\r\n    }\r\n\r\n    \/\/ \u5b9f\u9a13\uff11\u306e\u63cf\u753b\r\n    map&lt;string, string&gt; args1{\r\n            {\"label\", \"emplace_back()\"},\r\n            {\"c\", \"blue\"}\r\n    };\r\n    plt::plot(x, results1, args1);\r\n\r\n    \/\/ \u5b9f\u9a13\uff12\u306e\u63cf\u753b\r\n    map&lt;string, string&gt; args2{\r\n            {\"label\", \"push_back()\"},\r\n            {\"c\", \"orange\"}\r\n    };\r\n    plt::plot(x, results2, args2);\r\n\r\n\r\n    plt::xlabel(\"vector size\");\r\n    plt::ylabel(\"elapsed time [sec]\");\r\n    plt::legend();\r\n    plt::save(\"result.png\");\r\n\r\n    return 0;\r\n\r\n\r\n}<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"CMakeLists_txt\"><\/span>CMakeLists.txt<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>matplotlibcpp\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306eCmakeLists.txt\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\uff0e<\/p>\n<p>\u9069\u5f53\u306b\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\uff0e<\/p>\n<pre class=\"lang:c++ decode:true\" title=\"CMakeLists\">cmake_minimum_required(VERSION 3.14)\r\nproject(expt)\r\n\r\nset(CMAKE_CXX_STANDARD 14)\r\n\r\nfind_package(Python3 COMPONENTS Development NumPy)\r\nadd_executable(expt main.cpp)\r\n\r\ntarget_include_directories(expt PRIVATE ${Python3_INCLUDE_DIRS} ${Python3_NumPy_INCLUDE_DIRS})\r\ntarget_link_libraries(expt Python3::Python Python3::NumPy)\r\n<\/pre>\n<p>\u304a\u3057\u307e\u3044\uff0e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3088\u304f\u3042\u308b\u8a71\uff0cpush_back()\u3068emplace_back()\u306e\u8a71\u984c\u306f\u7d50\u69cb\u3042\u3063\u3066\uff0c\u691c\u7d22\u3059\u308b\u3068\u305f\u304f\u3055\u3093\u51fa\u3066\u304d\u307e\u3059\uff0e\u305d\u3057\u3066\u7d50\u8ad6\u3068\u3057\u3066\u300c\u3068\u308a\u3042\u3048\u305aemplace_back()\u3092\u4f7f\u3063\u3068\u3051\u300d\u3068\u306a\u3063\u3066\u3044\u308b\u8a18\u4e8b\u304c\u591a\u3044\u3067\u3059\u306d\uff0e\u4eca\u307e\u3067\u79c1\u3082\u305d\u3046\u3057\u3066\u3044\u307e\u3057\u305f\u304c\uff0c\u3069\u306e\u7a0b\u5ea6\u901f\u304f\u306a\u308b\u306e\u304b\u306f\u6c17\u306b\u306a\u308a\u307e\u3059\u3088\u306d\uff0e\u65e9\u901f\u5b9f\u9a13\u3057\u3066\u307f\u307e\u3057\u3087\u3046\uff0e<\/p>\n","protected":false},"author":1,"featured_media":698,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[12,14,23,13],"_links":{"self":[{"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/posts\/685"}],"collection":[{"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/comments?post=685"}],"version-history":[{"count":13,"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/posts\/685\/revisions"}],"predecessor-version":[{"id":987,"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/posts\/685\/revisions\/987"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/media\/698"}],"wp:attachment":[{"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/media?parent=685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/categories?post=685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/tags?post=685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}