{"id":430,"date":"2019-04-18T14:30:09","date_gmt":"2019-04-18T05:30:09","guid":{"rendered":"http:\/\/hirlab.net\/nblog\/?p=430"},"modified":"2019-04-18T14:30:09","modified_gmt":"2019-04-18T05:30:09","slug":"c%e9%80%9f%e5%ba%a6%e5%ae%9f%e9%a8%93%e3%81%9d%e3%81%ae%ef%bc%93%ef%bc%81%e3%83%a1%e3%83%b3%e3%83%90%e5%a4%89%e6%95%b0%e3%81%a8this%e3%83%9d%e3%82%a4%e3%83%b3%e3%82%bf","status":"publish","type":"post","link":"https:\/\/hirlab.net\/nblog\/category\/programming\/art_430\/","title":{"rendered":"C++\u901f\u5ea6\u5b9f\u9a13\u305d\u306e\uff13\uff01\u30e1\u30f3\u30d0\u5909\u6570\u3068this\u30dd\u30a4\u30f3\u30bf"},"content":{"rendered":"<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p>\u66f4\u65b0\u306b\u7a7a\u304d\u304c\u3067\u304d\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u304c\uff0cC++\u901f\u5ea6\u5b9f\u9a13\u305d\u306e\uff13\u3067\u3059\uff01<\/p>\n<p>\u3061\u306a\u307f\u306b\u524d\u56de\u306f\uff0c<a href=\"https:\/\/hirlab.net\/nblog\/category\/programming\/art_316\/\">C++\u901f\u5ea6\u5b9f\u9a13\u305d\u306e\uff12\uff01vector\u914d\u5217\u306e\u6271\u3044\u306b\u3064\u3044\u3066<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u4eca\u56de\u306e\u30c6\u30fc\u30de\u306f\u30ba\u30d0\u30ea<strong>this\u30dd\u30a4\u30f3\u30bf<\/strong>\u3067\u3059\uff0e<\/p>\n<p>this\u30dd\u30a4\u30f3\u30bf\u306f\u30af\u30e9\u30b9\u306e<strong><mark>\u30e1\u30f3\u30d0\u95a2\u6570\u5185\u3067\u4f7f\u7528\u3067\u304d\u308b\uff0c\u81ea\u8eab\u306e\u30af\u30e9\u30b9\u3092\u6307\u3059\u30dd\u30a4\u30f3\u30bf<\/mark><\/strong>\u3067\u3059\uff0e<\/p>\n<p>&nbsp;<\/p>\n<h2>this\u30dd\u30a4\u30f3\u30bf<\/h2>\n<p><strong>this\u30dd\u30a4\u30f3\u30bf<\/strong>\u306f\uff0c\u901a\u5e38\u30e1\u30f3\u30d0\u95a2\u6570\u5185\u304b\u3089\u30e1\u30f3\u30d0\u5909\u6570\u3092\u547c\u3073\u51fa\u3059\u3068\u304d\u306b\u4f7f\u7528\u3057\u307e\u3059\u304c\uff0c\u3082\u3057\u305d\u306e\u30e1\u30f3\u30d0\u95a2\u6570\u5185\u306b\u53c2\u7167\u3057\u305f\u3044\u30e1\u30f3\u30d0\u5909\u6570\u3068\u540c\u3058\u540d\u524d\u304c\u3092\u6301\u3063\u305f\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u304c\u7121\u3051\u308c\u3070\u7701\u7565\u304c\u53ef\u80fd\u3067\u3059\uff0e<\/p>\n<p>&nbsp;<\/p>\n<p>\u3053\u308c\u306fC\u8a00\u8a9e\u306b\u306f\u306a\u304fC++\u304b\u3089\u5c0e\u5165\u3055\u308c\u305f\u3088\u3046\u3067\u3059\uff0e<\/p>\n<p>\u3064\u307e\u308a\u3053\u3044\u3046\u3053\u3068\uff01<\/p>\n<pre class=\"lang:c++ decode:true\" title=\"\u30b3\u30fc\u30c9\u4f8b\">#include &amp;lt;iostream&gt;\r\nclass sample{\r\nprivate:\r\n    std::string str1 = \"member1\";\r\n    std::string str2 = \"member2\";\r\npublic:\r\n    void function();\r\n};\r\n\r\nvoid sample::function() {\r\n    \/\/ this\u30dd\u30a4\u30f3\u30bf\u3067\u30e1\u30f3\u30d0\u5909\u6570\u306b\u30a2\u30af\u30bb\u30b9\r\n    std::cout &lt;&lt; this-&gt;str1 &lt;&lt; std::endl;\r\n\r\n    \/\/ \u7701\u7565\u53ef\r\n    std::cout &lt;&lt; str1 &lt;&lt; std::endl;\r\n    \r\n    \/\/ \u305f\u3060\u3057\u540c\u3058\u540d\u524d\u306e\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u304c\u3042\u308b\u5834\u5408\u306f\r\n    \/\/ \u4f55\u3082\u3064\u3051\u306a\u3044\u3068\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u512a\u5148\u306b\u306a\u308b\r\n    std::string str2 = \"local\";\r\n    std::cout &lt;&lt; str2 &lt;&lt; std::endl;\r\n    std::cout &lt;&lt; this-&gt;str2 &lt;&lt; std::endl;\r\n}\r\n\r\nint main(){\r\n    sample s;\r\n\r\n    s.function();\r\n    return 0;\r\n}<\/pre>\n<pre class=\"lang:c++ highlight:0 decode:true \" title=\"\u5b9f\u884c\u7d50\u679c\">member1\r\nmember1\r\nlocal\r\nmember2<\/pre>\n<p>&nbsp;<\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\uff0c\u6b63\u76f4this\u30dd\u30a4\u30f3\u30bf\u306f\u7279\u306b\u4f7f\u308f\u306a\u304f\u3066\u3082\u4f55\u3068\u304b\u306a\u308b\u306e\u3067\u3059\u304c\uff0c\u660e\u793a\u7684\u306b\u5206\u304b\u308a\u3084\u3059\u3044\u4e0a\u306b\uff0c\u30bb\u30c3\u30bf\u30fc\u306a\u3069\u3067\u5f15\u6570\u306e\u540d\u524d\u3092\uff0c\u5b9f\u969b\u306b\u4ee3\u5165\u3059\u308b\u30e1\u30f3\u30d0\u5909\u6570\u3068\u540c\u3058\u306b\u8a2d\u5b9a\u3067\u304d\u308b\u306e\u3067\uff0c\u30b3\u30fc\u30c9\u306e\u53ef\u8aad\u6027\u306f\u5411\u4e0a\u3059\u308b\u304b\u3068\u601d\u3044\u307e\u3059\uff0e<\/p>\n<p>&nbsp;<\/p>\n<p>\u305d\u3093\u306a\u308f\u3051\u3067\uff0c\u50d5\u306f\u57fa\u672c\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3067\u540c\u3058\u540d\u524d\u304c\u7121\u304f\u3068\u3082\uff0cthis\u30dd\u30a4\u30f3\u30bf\u306f\u3088\u304f\u4f7f\u3063\u3066\u3044\u307e\u3059\uff0e<\/p>\n<p>&nbsp;<\/p>\n<h2>\u5b9f\u9a13\u76ee\u7684<\/h2>\n<p>\u3055\u3066\uff0c\u4eca\u56de\u305d\u306ethis\u306b\u95a2\u3059\u308b\u901f\u5ea6\u5b9f\u9a13\u3092\u3059\u308b\u308f\u3051\u3067\u3059\u304c\uff0c\u679c\u305f\u3057\u3066<\/p>\n<p><strong><mark>this\u30dd\u30a4\u30f3\u30bf\u3092\u4ed8\u3051\u305f\u5834\u5408\u3068\u4ed8\u3051\u306a\u3044\u5834\u5408\u3067\u5b9f\u884c\u901f\u5ea6\u306b\u5dee\u306f\u51fa\u308b\u306e\u304b\uff0e<\/mark><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>\u3068\u3044\u3046\u7591\u554f\u304b\u3089\u5b9f\u9a13\u3092\u884c\u3063\u3066\u3044\u304d\u307e\u3059\uff0e<\/p>\n<p>\u307e\u305f\uff0c\u4e26\u884c\u3057\u3066\u95a2\u9023\u3057\u305f\u5b9f\u9a13\u3082\u884c\u3044\u307e\u3059\u3088\uff5e\uff0e<\/p>\n<p>&nbsp;<\/p>\n<h2>\u5b9f\u9a13\u6761\u4ef6<\/h2>\n<p>\u307e\u305a\u6bd4\u8f03\u3059\u308b\u6761\u4ef6\u3092\u7d39\u4ecb\u3057\u307e\u3059\uff0e<\/p>\n<p>\u3069\u306e\u5b9f\u9a13\u3067\u3082\u5171\u901a\u3057\u3066\u3044\u308b\u306e\u304c\uff0c\u4ee5\u4e0b\u306e<\/p>\n<pre class=\"lang:c++ decode:true\">class test{\r\nprivate:\r\n    double a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0, a7 = 0, a8 = 0, a9 = 0, a10 = 0;\r\n};<\/pre>\n<p>\u3068\u3044\u3046<span class=\"lang:c++ decode:true crayon-inline\">test<\/span>\u00a0\u30af\u30e9\u30b9\u306b\u5c5e\u3059\u308b<span class=\"lang:c++ decode:true crayon-inline \">double<\/span>\u00a0\u578b\u306e\u30e1\u30f3\u30d0\u5909\u657010\u500b\u306b100,000,000\u56de\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\uff0e<\/p>\n<p>\u305d\u308c\u3092100\u8a66\u884c\u884c\u3044\uff0c\u304b\u304b\u3063\u305f\u6642\u9593\u306e\u5e73\u5747\u5024\u3092\u6bd4\u8f03\u3059\u308b\u5f62\u3092\u3068\u308a\u307e\u3059\uff0e<\/p>\n<p>&nbsp;<\/p>\n<h3>\u5b9f\u9a130 (baseline)\uff1athis\u30dd\u30a4\u30f3\u30bf\u3092\u4f7f\u308f\u306a\u3044<\/h3>\n<pre class=\"lang:c++ decode:true \" title=\"\u5b9f\u9a130\u306e\u30b3\u30fc\u30c9\">\/**\r\n * \u30e1\u30f3\u30d0\u5909\u6570\u306bthis\u30dd\u30a4\u30f3\u30bf\u3092\u4f7f\u308f\u305a\u306b\u30a2\u30af\u30bb\u30b9\uff01\r\n *\/\r\nvoid test::exp1_0() {\r\n\r\n    for( int i = 0; i &lt; 100000000; ++i ){\r\n        auto a = a1 + a2 + a3 + a4 + a5 +\r\n                 a6 + a7 + a8 + a9 + a10;\r\n    }\r\n}<\/pre>\n<h3>\u5b9f\u9a131\uff1athis\u30dd\u30a4\u30f3\u30bf\u3092\u4f7f\u3046<\/h3>\n<pre class=\"lang:c++ decode:true\" title=\"\u5b9f\u9a131\u306e\u30b3\u30fc\u30c9\">\/**\r\n * \u30e1\u30f3\u30d0\u5909\u6570\u306bthis\u30dd\u30a4\u30f3\u30bf\u3092\u4f7f\u3063\u3066\u30a2\u30af\u30bb\u30b9\uff01\r\n *\/\r\nvoid test::exp1_1() {\r\n\r\n    for( int i = 0; i &lt; 100000000; ++i ){\r\n        auto a = this-&gt;a1 + this-&gt;a2 + this-&gt;a3 + this-&gt;a4 + this-&gt;a5 +\r\n                 this-&gt;a6 + this-&gt;a7 + this-&gt;a8 + this-&gt;a9 + this-&gt;a10;\r\n    }\r\n}<\/pre>\n<h3>\u5b9f\u9a132\uff1a\u4e88\u3081\u30ed\u30fc\u30ab\u30eb\u306bthis\u30dd\u30a4\u30f3\u30bf\u3092\u78ba\u4fdd\u3057\u3066\u304a\u304f<\/h3>\n<pre class=\"lang:c++ decode:true\" title=\"\u5b9f\u9a132\u306e\u30b3\u30fc\u30c9\">\/**\r\n * \u4e88\u3081\u30af\u30e9\u30b9\u30dd\u30a4\u30f3\u30bf\u3092\u95a2\u6570\u5185\u3067\u78ba\u4fdd\u3059\u308b\uff0e\r\n *\/\r\nvoid test::exp1_2() {\r\n\r\n    test* t = this;\r\n    for( int i = 0; i &lt; 100000000; ++i ){\r\n        auto a = t-&gt;a1 + t-&gt;a2 + t-&gt;a3 + t-&gt;a4 + t-&gt;a5 +\r\n                 t-&gt;a6 + t-&gt;a7 + t-&gt;a8 + t-&gt;a9 + t-&gt;a10;\r\n    }\r\n}<\/pre>\n<h3>\u5b9f\u9a133\uff1a\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u306b\u30e1\u30f3\u30d0\u5909\u6570\u3092this\u3092\u4f7f\u3063\u3066\u78ba\u4fdd\u3057\u3066\u304a\u304f<\/h3>\n<pre class=\"lang:c++ decode:true \" title=\"\u5b9f\u9a133\u306e\u30b3\u30fc\u30c9\">\/**\r\n * \u6700\u521d\u306b\u30ed\u30fc\u30ab\u30eb\u306a\u5909\u6570\u3068\u3057\u3066\uff0c\u30e1\u30f3\u30d0\u5909\u6570\u3092\u4fdd\u6301\uff0e\r\n *\/\r\nvoid test::exp1_3() {\r\n    double a1 = this-&gt;a1;\r\n    double a2 = this-&gt;a2;\r\n    double a3 = this-&gt;a3;\r\n    double a4 = this-&gt;a4;\r\n    double a5 = this-&gt;a5;\r\n    double a6 = this-&gt;a6;\r\n    double a7 = this-&gt;a7;\r\n    double a8 = this-&gt;a8;\r\n    double a9 = this-&gt;a9;\r\n    double a10 = this-&gt;a10;\r\n    for( int i = 0; i &lt; 100000000; ++i ){\r\n        auto a = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10;\r\n    }\r\n}<\/pre>\n<h3>\u5b9f\u9a134\uff1a\u30cf\u30a4\u30d6\u30ea\u30c3\u30c9<\/h3>\n<pre class=\"lang:c++ decode:true\" title=\"\u5b9f\u9a134\u306e\u30b3\u30fc\u30c9\">\/**\r\n * \u30cf\u30a4\u30d6\u30ea\u30c3\u30c9\u578b\uff0e\r\n *\/\r\nvoid test::exp1_4() {\r\n    test* t = this;\r\n    double a1 = t-&gt;a1;\r\n    double a2 = t-&gt;a2;\r\n    double a3 = t-&gt;a3;\r\n    double a4 = t-&gt;a4;\r\n    double a5 = t-&gt;a5;\r\n    double a6 = t-&gt;a6;\r\n    double a7 = t-&gt;a7;\r\n    double a8 = t-&gt;a8;\r\n    double a9 = t-&gt;a9;\r\n    double a10 = t-&gt;a10;\r\n    for( int i = 0; i &lt; 100000000; ++i ){\r\n        auto a = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10;\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0a5\u3064\u306e\u6761\u4ef6\u3067\u6bd4\u8f03\u3057\u3066\u3044\u304d\u307e\u3059\uff0e<\/p>\n<h3>\u5b9f\u884c\u74b0\u5883<\/h3>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<td>IDE<\/td>\n<td>CLion 2018.3.3 \u00a9 Jetbrains<\/td>\n<\/tr>\n<tr>\n<td>CPU<\/td>\n<td>Intel(R) Core(TM) i7-5500U CPU<br \/>\n@2.40GHz(4 CPUs)<\/td>\n<\/tr>\n<tr>\n<td>\u30e1\u30e2\u30ea<\/td>\n<td>8GB<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h2>\u5b9f\u9a13\u7d50\u679c<\/h2>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<td>\u5b9f\u9a130<\/td>\n<td>0.45108 s<\/td>\n<\/tr>\n<tr>\n<td>\u5b9f\u9a131<\/td>\n<td>0.46661 s<\/td>\n<\/tr>\n<tr>\n<td>\u5b9f\u9a132<\/td>\n<td>0.43032 s<\/td>\n<\/tr>\n<tr>\n<td><span style=\"color: #ff0000;\">\u5b9f\u9a133<\/span><\/td>\n<td><span style=\"color: #ff0000;\">0.32787 s<\/span><\/td>\n<\/tr>\n<tr>\n<td>\u5b9f\u9a134<\/td>\n<td>0.35778 s<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u306a\u3093\u3068\uff0c\u5b9f\u9a133\u304c\u4e00\u756a\u901f\u304b\u3063\u305f\uff0e<\/p>\n<p>\u3068\u306b\u304b\u304f\u5206\u304b\u3063\u305f\u3053\u3068\u306f\uff0c<\/p>\n<ol>\n<li><strong><span style=\"color: #000000;\">this\u30dd\u30a4\u30f3\u30bf\u306e\u6709\u7121\u306f\u5b9f\u884c\u901f\u5ea6\u306b\u5f71\u97ff\u304c\u307b\u3068\u3093\u3069\u51fa\u306a\u3044\uff0e<\/span><\/strong><\/li>\n<li><strong><span style=\"color: #000000;\">this\u30dd\u30a4\u30f3\u30bf\u3092\u30ed\u30fc\u30ab\u30eb\u306b\u78ba\u4fdd\u3057\u3066\u3082\u5b9f\u884c\u901f\u5ea6\u306b\u5f71\u97ff\u304c\u307b\u3068\u3093\u3069\u51fa\u306a\u3044\uff0e<\/span><\/strong><br \/>\n<strong><span style=\"color: #000000;\">(\u3080\u3057\u308d\u3072\u3068\u624b\u9593\u5897\u3048\u3066\u9045\u304f\u306a\u308b??)<\/span><\/strong><\/li>\n<li><strong><span style=\"color: #000000;\">\u30e1\u30f3\u30d0\u5909\u6570\u3078\u306e\u30a2\u30af\u30bb\u30b9\u306f\u6642\u9593\u304c\u304b\u304b\u308b\u306e\u3067\uff0c\u4f55\u5ea6\u3082\u53c2\u7167\u3059\u308b\u5834\u5408\u306f\u30ed\u30fc\u30ab\u30eb\u306b\u30b3\u30d4\u30fc\u3057\u3066\u304a\u304f\u306e\u304c\u5409\uff0e<\/span><\/strong><\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\uff0e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306f\u3058\u3081\u306b \u66f4\u65b0\u306b\u7a7a\u304d\u304c\u3067\u304d\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u304c\uff0cC++\u901f\u5ea6\u5b9f\u9a13\u305d\u306e\uff13\u3067\u3059\uff01 \u3061\u306a\u307f\u306b\u524d\u56de\u306f\uff0cC++\u901f\u5ea6\u5b9f\u9a13\u305d\u306e\uff12\uff01vector\u914d\u5217\u306e\u6271\u3044\u306b\u3064\u3044\u3066 &nbsp; \u4eca\u56de\u306e\u30c6\u30fc\u30de\u306f\u30ba\u30d0\u30eathis\u30dd\u30a4\u30f3\u30bf\u3067\u3059\uff0e this\u30dd\u30a4\u30f3\u30bf\u306f\u30af [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":432,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[12,23,13],"class_list":["post-430","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming","tag-cpp","tag-23","tag-faster"],"_links":{"self":[{"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/posts\/430","targetHints":{"allow":["GET"]}}],"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=430"}],"version-history":[{"count":17,"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/posts\/430\/revisions"}],"predecessor-version":[{"id":448,"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/posts\/430\/revisions\/448"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/media\/432"}],"wp:attachment":[{"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/media?parent=430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/categories?post=430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hirlab.net\/nblog\/wp-json\/wp\/v2\/tags?post=430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}