{"id":2780,"date":"2018-10-06T01:42:49","date_gmt":"2018-10-05T16:42:49","guid":{"rendered":"https:\/\/1bed.allright.life\/?p=2780"},"modified":"2020-04-18T19:26:04","modified_gmt":"2020-04-18T10:26:04","slug":"post-2780","status":"publish","type":"post","link":"https:\/\/1bed.allright.life\/?p=2780","title":{"rendered":"PowerShell \u3067\u5168\u89d2\u6570\u5b57\u3092\u534a\u89d2\u306b\u7f6e\u304d\u63db\u3048\u308b\u30b3\u30fc\u30c9\u306e\u5b9f\u884c\u6642\u9593\u3092\u8a08\u6e2c"},"content":{"rendered":"<h2>\u7d4c\u7def<\/h2>\n<p>PowerShell \u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u79fb\u884c\u3092\u884c\u3046\u6642\u306b\u3001\u30c7\u30fc\u30bf\u6574\u5099\u306e\u305f\u3081\u306b\u5168\u89d2\u3092\u534a\u89d2\u306b\u3059\u308b&#8230; \u3088\u304f\u3042\u308b\u8a71\u3060\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u5148\u65e5\u4ed5\u4e8b\u3067\u305d\u306e\u5834\u9762\u3067\u8272\u3005\u8abf\u67fb\u3059\u308b\u6642\u9593\u304c\u306a\u304b\u3063\u305f\u306e\u3067\u30ac\u30fc\u30c3\u3068\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u307e\u3057\u305f\u304c\u3001\u300c\u3042\u308c\u306f\u9045\u3044\u306e\u3067\u306f\uff1f\u300d\u3068\u601d\u3063\u3066\u3001\u30b5\u30c3\u3068\u601d\u3044\u6d6e\u304b\u3076\u65b9\u6cd5\u3067\u8a08\u6e2c\u3057\u3066\u307f\u307e\u3057\u305f<\/p>\n<h2>\u74b0\u5883<\/h2>\n<h3>\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u74b0\u5883<\/h3>\n<ul>\n<li>Windows 10 Pro<\/li>\n<li>PowerShell 5.1.17134.228<\/li>\n<li>Surface Pro 4 (Core i5-6300U)<\/li>\n<\/ul>\n<h3>\u30c6\u30b9\u30c8\u65b9\u6cd5<\/h3>\n<p>\u6b21\u306e\u30c7\u30fc\u30bf\u306e\u5168\u89d2\u6570\u5b57\u3092\u534a\u89d2\u6570\u5b57\u306b 1,000,000 \u56de\u7f6e\u304d\u63db\u3048\u308b\u3002<\/p>\n<pre><code class=\"language-powershell\">$data = &quot;\uff12\uff10\uff11\uff18\u5e74\uff10\uff19\u6708\uff12\uff16\u65e5\u6c34\u66dc\u65e5\u306e\u6c96\u7e04\u306e\u5929\u6c17\u306f\u66c7\u308a\u6642\u3005\u6674\u308c\u3001\n\u6700\u9ad8\u6c17\u6e29\u306f\uff13\uff11\u2103\u3001\u6700\u4f4e\u6c17\u6e29\u306f\uff12\uff16\u2103\u306e\u4e88\u60f3\u3067\u3059\u3002&quot;<\/code><\/pre>\n<h2>\u30b3\u30fc\u30c9<\/h2>\n<h3>1. System.String \u306e Replace \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046<\/h3>\n<pre><code class=\"language-powershell\">$data = &quot;\uff12\uff10\uff11\uff18\u5e74\uff10\uff19\u6708\uff12\uff16\u65e5\u6c34\u66dc\u65e5\u306e\u6c96\u7e04\u306e\u5929\u6c17\u306f\u66c7\u308a\u6642\u3005\u6674\u308c\u3001\n\u6700\u9ad8\u6c17\u6e29\u306f\uff13\uff11\u2103\u3001\u6700\u4f4e\u6c17\u6e29\u306f\uff12\uff16\u2103\u306e\u4e88\u60f3\u3067\u3059\u3002&quot;\n\nMeasure-Command {\n\n    for($i = 0; $i -lt 1000000; $i++) {\n        [void]$data.Replace(&#039;\uff10&#039;, &#039;0&#039;).Replace(&#039;\uff11&#039;, &#039;1&#039;).Replace(&#039;\uff12&#039;, &#039;2&#039;).Replace(&#039;\uff13&#039;, &#039;3&#039;).Replace(&#039;\uff14&#039;, &#039;4&#039;).Replace(&#039;\uff15&#039;, &#039;5&#039;).Replace(&#039;\uff16&#039;, &#039;6&#039;).Replace(&#039;\uff17&#039;, &#039;7&#039;).Replace(&#039;\uff18&#039;, &#039;8&#039;).Replace(&#039;\uff19&#039;, &#039;9&#039;)\n    }\n\n}\n\nDays              : 0\nHours             : 0\nMinutes           : 0\nSeconds           : 3\nMilliseconds      : 799\nTicks             : 37996428\nTotalDays         : 4.39773472222222E-05\nTotalHours        : 0.00105545633333333\nTotalMinutes      : 0.06332738\nTotalSeconds      : 3.7996428\nTotalMilliseconds : 3799.6428<\/code><\/pre>\n<h3>2. PowerShell \u306e -replace \u6f14\u7b97\u5b50<\/h3>\n<pre><code class=\"language-powershell\">$data = &quot;\uff12\uff10\uff11\uff18\u5e74\uff10\uff19\u6708\uff12\uff16\u65e5\u6c34\u66dc\u65e5\u306e\u6c96\u7e04\u306e\u5929\u6c17\u306f\u66c7\u308a\u6642\u3005\u6674\u308c\u3001\n\u6700\u9ad8\u6c17\u6e29\u306f\uff13\uff11\u2103\u3001\u6700\u4f4e\u6c17\u6e29\u306f\uff12\uff16\u2103\u306e\u4e88\u60f3\u3067\u3059\u3002&quot;\n\nMeasure-Command {\n\n    for($i = 0; $i -lt 1000000; $i++) {\n        [void]$data -replace &quot;\uff10&quot; , &quot;0&quot; -replace &quot;\uff11&quot;, &quot;1&quot; -replace &quot;\uff12&quot;, &quot;2&quot; -replace &quot;\uff13&quot;, &quot;3&quot; -replace &quot;\uff14&quot;, &quot;4&quot; -replace &quot;\uff15&quot;, &quot;5&quot; -replace &quot;\uff16&quot; , &quot;6&quot; -replace &quot;\uff17&quot;, &quot;7&quot; -replace &quot;\uff18&quot;, &quot;8&quot; -replace &quot;\uff19&quot;, &quot;9&quot;\n    }\n\n}\n\nDays              : 0\nHours             : 0\nMinutes           : 0\nSeconds           : 6\nMilliseconds      : 475\nTicks             : 64756627\nTotalDays         : 7.49497997685185E-05\nTotalHours        : 0.00179879519444444\nTotalMinutes      : 0.107927711666667\nTotalSeconds      : 6.4756627\nTotalMilliseconds : 6475.6627<\/code><\/pre>\n<h3>3. C# \u3067\u7f6e\u304d\u63db\u3048\u308b1<\/h3>\n<pre><code class=\"language-powershell\">$data = &quot;\uff12\uff10\uff11\uff18\u5e74\uff10\uff19\u6708\uff12\uff16\u65e5\u6c34\u66dc\u65e5\u306e\u6c96\u7e04\u306e\u5929\u6c17\u306f\u66c7\u308a\u6642\u3005\u6674\u308c\u3001\n\u6700\u9ad8\u6c17\u6e29\u306f\uff13\uff11\u2103\u3001\u6700\u4f4e\u6c17\u6e29\u306f\uff12\uff16\u2103\u306e\u4e88\u60f3\u3067\u3059\u3002&quot;\n\nMeasure-Command {\n\n# \u534a\u89d2\u3092\u5168\u89d2\u306b\u5909\u63db\u3059\u308b\nAdd-Type -Language CSharp -TypeDefinition @&quot;\nusing System;\n\npublic class Helper\n{\n    public string DatetimeChar2Han(string str)\n    {\n        try {\n            return str.Replace(&#039;\uff10&#039;, &#039;0&#039;).Replace(&#039;\uff11&#039;, &#039;1&#039;).Replace(&#039;\uff12&#039;, &#039;2&#039;).Replace(&#039;\uff13&#039;, &#039;3&#039;).Replace(&#039;\uff14&#039;, &#039;4&#039;).Replace(&#039;\uff15&#039;, &#039;5&#039;).Replace(&#039;\uff16&#039;, &#039;6&#039;).Replace(&#039;\uff17&#039;, &#039;7&#039;).Replace(&#039;\uff18&#039;, &#039;8&#039;).Replace(&#039;\uff19&#039;, &#039;9&#039;);\n        } catch {\n            return str;\n        }\n    }\n}\n&quot;@\n    $helper = [Helper]::new()\n\n    for($i = 0; $i -lt 1000000; $i++) {\n        [void]$helper.DatetimeChar2Han($data)\n    }\n}\n\nDays              : 0\nHours             : 0\nMinutes           : 0\nSeconds           : 3\nMilliseconds      : 251\nTicks             : 32512049\nTotalDays         : 3.76296863425926E-05\nTotalHours        : 0.000903112472222222\nTotalMinutes      : 0.0541867483333333\nTotalSeconds      : 3.2512049\nTotalMilliseconds : 3251.2049<\/code><\/pre>\n<h3>4. C# \u3067\u7f6e\u304d\u63db\u3048\u308b2 (\u5b9f\u306f\u4eca\u56de\u3053\u306e\u30d1\u30bf\u30fc\u30f3\u3067\u3084\u3063\u305f)<\/h3>\n<pre><code class=\"language-powershell\">$data = &quot;\uff12\uff10\uff11\uff18\u5e74\uff10\uff19\u6708\uff12\uff16\u65e5\u6c34\u66dc\u65e5\u306e\u6c96\u7e04\u306e\u5929\u6c17\u306f\u66c7\u308a\u6642\u3005\u6674\u308c\u3001\n\u6700\u9ad8\u6c17\u6e29\u306f\uff13\uff11\u2103\u3001\u6700\u4f4e\u6c17\u6e29\u306f\uff12\uff16\u2103\u306e\u4e88\u60f3\u3067\u3059\u3002&quot;\n\nMeasure-Command {\n\n# \u534a\u89d2\u3092\u5168\u89d2\u306b\u5909\u63db\u3059\u308b\nAdd-Type -Language CSharp -TypeDefinition @&quot;\nusing System;\n\npublic class Helper\n{\n    public string[] convertFrom = new string[] {&quot;\uff10&quot;,&quot;\uff11&quot;,&quot;\uff12&quot;,&quot;\uff13&quot;,&quot;\uff14&quot;,&quot;\uff15&quot;,&quot;\uff16&quot;,&quot;\uff17&quot;,&quot;\uff18&quot;,&quot;\uff19&quot;};\n    public string[] convertTo   = new string[] {&quot;0&quot;,&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;};\n\n    public string ZenNumber2Han(string str)\n    {\n        try {\n            string buf = str;\n            for(int i = 0; i &lt; convertFrom.Length; i++) {\n                buf = buf.Replace(convertFrom[i], convertTo[i]);\n            }\n            return buf;\n        } catch {\n            return str;\n        }\n    }\n}\n&quot;@\n    $helper = [Helper]::new()\n\n    for($i = 0; $i -lt 1000000; $i++) {\n        [void]$helper.ZenNumber2Han($data)\n    }\n}\n\nDays              : 0\nHours             : 0\nMinutes           : 0\nSeconds           : 4\nMilliseconds      : 602\nTicks             : 46021738\nTotalDays         : 5.3265900462963E-05\nTotalHours        : 0.00127838161111111\nTotalMinutes      : 0.0767028966666667\nTotalSeconds      : 4.6021738\nTotalMilliseconds : 4602.1738<\/code><\/pre>\n<h2>\u8003\u5bdf<\/h2>\n<p>System.String \u306e Replace \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u306e\u304c\u4e00\u756a\u901f\u304f\u3001\u4e14\u3064\u3001C# \u306e\u30b3\u30fc\u30c9\u3067\u66f8\u3044\u305f\u307b\u3046\u304c\u901f\u305d\u3046<\/p>\n<p>PowerShell \u306e -replace \u6f14\u7b97\u5b50\u306f\u3001\u6b63\u898f\u8868\u73fe\u304c\u4f7f\u3048\u308b\u306e\u3067\u4e00\u6982\u306b\u6bd4\u3079\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u304c\u3001\u5358\u7d14\u306a\u7f6e\u304d\u63db\u3048\u306a\u3089 System.String \u306e Replace \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u306e\u304c\u5409\u304b\u3082<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7d4c\u7def PowerShell \u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u79fb\u884c\u3092\u884c\u3046\u6642\u306b\u3001\u30c7\u30fc\u30bf\u6574\u5099\u306e\u305f\u3081\u306b\u5168\u89d2\u3092\u534a\u89d2\u306b\u3059\u308b&#8230; \u3088\u304f\u3042\u308b\u8a71\u3060\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u5148\u65e5\u4ed5\u4e8b\u3067\u305d\u306e\u5834\u9762\u3067\u8272\u3005\u8abf\u67fb\u3059\u308b\u6642\u9593\u304c\u306a\u304b\u3063\u305f\u306e\u3067\u30ac\u30fc\u30c3\u3068\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3057\u307e\u3057\u305f\u304c\u3001\u300c\u3042 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[62],"class_list":["post-2780","post","type-post","status-publish","format-standard","hentry","category-program","tag-powershell"],"_links":{"self":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2780"}],"version-history":[{"count":7,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2780\/revisions"}],"predecessor-version":[{"id":3101,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=\/wp\/v2\/posts\/2780\/revisions\/3101"}],"wp:attachment":[{"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1bed.allright.life\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}