{"id":107,"date":"2015-02-11T22:44:20","date_gmt":"2015-02-11T14:44:20","guid":{"rendered":"http:\/\/sqrt-1.me\/?p=107"},"modified":"2016-11-19T15:01:00","modified_gmt":"2016-11-19T07:01:00","slug":"%e5%af%b9c%e8%af%ad%e8%a8%80%e4%b8%ad%e4%b8%8d%e5%90%8c%e7%b1%bb%e5%9e%8b%e6%95%b0%e6%8d%ae%e8%ae%a1%e7%ae%97%e9%80%9f%e5%ba%a6%e7%9a%84%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"https:\/\/sqrt-1.me\/?p=107","title":{"rendered":"\u5bf9C\u8bed\u8a00\u4e2d\u4e0d\u540c\u7c7b\u578b\u6570\u636e\u8ba1\u7b97\u901f\u5ea6\u7684\u6d4b\u8bd5"},"content":{"rendered":"<p>\u6211\u5bf9C\u8bed\u8a00\u4e2d\u5404\u79cd\u6570\u636e\u7c7b\u578b\u7684\u56db\u5219\u8fd0\u7b97\u901f\u5ea6\u8fdb\u884c\u4e86\u6d4b\u8bd5\u3002<\/p>\n<p>\u64cd\u4f5c\u7cfb\u7edf\uff1aWindows 8.1 \u4e13\u4e1a\u7248 (64\u4f4d)<br \/>\n\u7f16\u8bd1\u5668\uff1aGCC 4.8.1 64-bit Release (\u672a\u5f00\u4efb\u4f55\u4f18\u5316)<br \/>\n\u5904\u7406\u5668\uff1aIntel Core i7-4702MQ<\/p>\n<p>\u6d4b\u8bd5\u6570\u636e\u9009\u62e9\u7684\u90fd\u662f12345\u548c123<\/p>\n<p>\u6d4b\u8bd5\u6e90\u7a0b\u5e8f\uff1a<\/p>\n<p><!--more--><\/p>\n<pre class=\"lang:c decode:true \" >\r\n#include&lt;stdio.h&gt;\r\n#include&lt;time.h&gt;\r\n\r\n#define test(expr){\\\r\n    printf(&quot;test: %s 100000000 times\\n&quot;,#expr);\\\r\n    sum=0;\\\r\n    for(j=0;j&lt;10;j++){\\\r\n        start=clock();\\\r\n        for(i=0;i&lt;1000000;i++){\\\r\n            expr;expr;expr;expr;expr;expr;expr;expr;expr;expr;\\\r\n            expr;expr;expr;expr;expr;expr;expr;expr;expr;expr;\\\r\n            expr;expr;expr;expr;expr;expr;expr;expr;expr;expr;\\\r\n            expr;expr;expr;expr;expr;expr;expr;expr;expr;expr;\\\r\n            expr;expr;expr;expr;expr;expr;expr;expr;expr;expr;\\\r\n            expr;expr;expr;expr;expr;expr;expr;expr;expr;expr;\\\r\n            expr;expr;expr;expr;expr;expr;expr;expr;expr;expr;\\\r\n            expr;expr;expr;expr;expr;expr;expr;expr;expr;expr;\\\r\n            expr;expr;expr;expr;expr;expr;expr;expr;expr;expr;\\\r\n            expr;expr;expr;expr;expr;expr;expr;expr;expr;expr;\\\r\n        }\\\r\n        end=clock();\\\r\n        t=(double)(end-start)\/CLOCKS_PER_SEC;\\\r\n        printf(&quot;%3d %.3fs&quot;,j+1,t);\\\r\n        if(j%5==4)printf(&quot;\\n&quot;);\\\r\n        sum+=t;\\\r\n    }\\\r\n    printf(&quot;Avg %.3fs\\n\\n&quot;,sum\/10);\\\r\n}\r\n\r\nint main(){\r\n    clock_t start,end;\r\n    double t,sum;\r\n    register int i,j;\r\n    short short1=12345,short2=123,short3;\r\n    long long1=12345,long2=123,long3;\r\n    long long longlong1=12345,longlong2=123,longlong3;\r\n    float float1=12345.0,float2=123.0,float3;\r\n    double double1=12345.0,double2=123.0,double3;\r\n    long double longdouble1=12345.0,longdouble2=123.0,longdouble3;\r\n\r\n    test(NULL)\r\n    test(short3=short1+short2)\r\n    test(short3=short1-short2)\r\n    test(short3=short1*short2)\r\n    test(short3=short1\/short2)\r\n    test(short3=short1%short2)\r\n    test(long3=long1+long2)\r\n    test(long3=long1-long2)\r\n    test(long3=long1*long2)\r\n    test(long3=long1\/long2)\r\n    test(long3=long1%long2)\r\n    test(longlong3=longlong1+longlong2)\r\n    test(longlong3=longlong1-longlong2)\r\n    test(longlong3=longlong1*longlong2)\r\n    test(longlong3=longlong1\/longlong2)\r\n    test(longlong3=longlong1%longlong2)\r\n    test(float3=float1+float2)\r\n    test(float3=float1-float2)\r\n    test(float3=float1*float2)\r\n    test(float3=float1\/float2)\r\n    test(double3=double1+double2)\r\n    test(double3=double1-double2)\r\n    test(double3=double1*double2)\r\n    test(double3=double1\/double2)\r\n    test(longdouble3=longdouble1+longdouble2)\r\n    test(longdouble3=longdouble1-longdouble2)\r\n    test(longdouble3=longdouble1*longdouble2)\r\n    test(longdouble3=longdouble1\/longdouble2)\r\n\r\n    return 0;\r\n}\r\n<\/pre>\n<p>\u7a0b\u5e8f\u8f93\u51fa\uff1a<\/p>\n<pre>\r\ntest: NULL 100000000 times\r\n1 0.000s 2 0.000s 3 0.000s 4 0.000s 5 0.000s\r\n6 0.000s 7 0.000s 8 0.000s 9 0.000s 10 0.000s\r\nAvg 0.000s\r\n\r\ntest: short3=short1+short2 100000000 times\r\n1 0.031s 2 0.047s 3 0.031s 4 0.031s 5 0.047s\r\n6 0.031s 7 0.032s 8 0.046s 9 0.032s 10 0.031s\r\nAvg 0.036s\r\n\r\ntest: short3=short1-short2 100000000 times\r\n1 0.047s 2 0.047s 3 0.047s 4 0.078s 5 0.047s\r\n6 0.046s 7 0.063s 8 0.047s 9 0.047s 10 0.046s\r\nAvg 0.052s\r\n\r\ntest: short3=short1*short2 100000000 times\r\n1 0.032s 2 0.047s 3 0.031s 4 0.047s 5 0.047s\r\n6 0.062s 7 0.031s 8 0.047s 9 0.032s 10 0.031s\r\nAvg 0.041s\r\n\r\ntest: short3=short1\/short2 100000000 times\r\n1 0.328s 2 0.422s 3 0.297s 4 0.390s 5 0.282s\r\n6 0.343s 7 0.297s 8 0.375s 9 0.360s 10 0.375s\r\nAvg 0.347s\r\n\r\ntest: short3=short1%short2 100000000 times\r\n1 0.390s 2 0.281s 3 0.344s 4 0.281s 5 0.297s\r\n6 0.282s 7 0.296s 8 0.282s 9 0.359s 10 0.313s\r\nAvg 0.313s\r\n\r\ntest: long3=long1+long2 100000000 times\r\n1 0.031s 2 0.047s 3 0.031s 4 0.031s 5 0.063s\r\n6 0.047s 7 0.031s 8 0.047s 9 0.031s 10 0.031s\r\nAvg 0.039s\r\n\r\ntest: long3=long1-long2 100000000 times\r\n1 0.063s 2 0.047s 3 0.046s 4 0.047s 5 0.047s\r\n6 0.047s 7 0.047s 8 0.047s 9 0.047s 10 0.047s\r\nAvg 0.048s\r\n\r\ntest: long3=long1*long2 100000000 times\r\n1 0.031s 2 0.047s 3 0.031s 4 0.031s 5 0.047s\r\n6 0.031s 7 0.032s 8 0.031s 9 0.047s 10 0.031s\r\nAvg 0.036s\r\n\r\ntest: long3=long1\/long2 100000000 times\r\n1 0.281s 2 0.313s 3 0.343s 4 0.313s 5 0.266s\r\n6 0.281s 7 0.344s 8 0.328s 9 0.312s 10 0.281s\r\nAvg 0.306s\r\n\r\ntest: long3=long1%long2 100000000 times\r\n1 0.313s 2 0.281s 3 0.282s 4 0.343s 5 0.297s\r\n6 0.438s 7 0.328s 8 0.281s 9 0.344s 10 0.281s\r\nAvg 0.319s\r\n\r\ntest: longlong3=longlong1+longlong2 100000000 times\r\n1 0.031s 2 0.063s 3 0.047s 4 0.031s 5 0.047s\r\n6 0.031s 7 0.031s 8 0.047s 9 0.031s 10 0.032s\r\nAvg 0.039s\r\n\r\ntest: longlong3=longlong1-longlong2 100000000 times\r\n1 0.093s 2 0.047s 3 0.047s 4 0.047s 5 0.063s\r\n6 0.109s 7 0.078s 8 0.047s 9 0.047s 10 0.047s\r\nAvg 0.063s\r\n\r\ntest: longlong3=longlong1*longlong2 100000000 times\r\n1 0.062s 2 0.047s 3 0.031s 4 0.032s 5 0.046s\r\n6 0.032s 7 0.031s 8 0.031s 9 0.031s 10 0.047s\r\nAvg 0.039s\r\n\r\ntest: longlong3=longlong1\/longlong2 100000000 times\r\n1 0.985s 2 0.953s 3 0.984s 4 0.891s 5 0.969s\r\n6 0.906s 7 0.953s 8 1.062s 9 0.876s 10 0.921s\r\nAvg 0.950s\r\n\r\ntest: longlong3=longlong1%longlong2 100000000 times\r\n1 0.907s 2 1.015s 3 0.922s 4 1.031s 5 1.079s\r\n6 0.937s 7 0.875s 8 0.938s 9 1.015s 10 1.000s\r\nAvg 0.972s\r\n\r\ntest: float3=float1+float2 100000000 times\r\n1 0.047s 2 0.031s 3 0.032s 4 0.031s 5 0.047s\r\n6 0.031s 7 0.031s 8 0.047s 9 0.031s 10 0.063s\r\nAvg 0.039s\r\n\r\ntest: float3=float1-float2 100000000 times\r\n1 0.047s 2 0.031s 3 0.031s 4 0.031s 5 0.047s\r\n6 0.032s 7 0.031s 8 0.031s 9 0.047s 10 0.062s\r\nAvg 0.039s\r\n\r\ntest: float3=float1*float2 100000000 times\r\n1 0.032s 2 0.031s 3 0.047s 4 0.078s 5 0.031s\r\n6 0.047s 7 0.031s 8 0.032s 9 0.031s 10 0.047s\r\nAvg 0.041s\r\n\r\ntest: float3=float1\/float2 100000000 times\r\n1 0.265s 2 0.266s 3 0.250s 4 0.250s 5 0.234s\r\n6 0.250s 7 0.266s 8 0.234s 9 0.250s 10 0.266s\r\nAvg 0.253s\r\n\r\ntest: double3=double1+double2 100000000 times\r\n1 0.047s 2 0.031s 3 0.031s 4 0.047s 5 0.032s\r\n6 0.031s 7 0.031s 8 0.047s 9 0.031s 10 0.031s\r\nAvg 0.036s\r\n\r\ntest: double3=double1-double2 100000000 times\r\n1 0.047s 2 0.032s 3 0.031s 4 0.031s 5 0.047s\r\n6 0.031s 7 0.031s 8 0.032s 9 0.047s 10 0.031s\r\nAvg 0.036s\r\n\r\ntest: double3=double1*double2 100000000 times\r\n1 0.031s 2 0.031s 3 0.047s 4 0.031s 5 0.032s\r\n6 0.047s 7 0.031s 8 0.031s 9 0.047s 10 0.094s\r\nAvg 0.042s\r\n\r\ntest: double3=double1\/double2 100000000 times\r\n1 0.547s 2 0.500s 3 0.531s 4 0.719s 5 0.484s\r\n6 0.484s 7 0.500s 8 0.500s 9 0.485s 10 0.531s\r\nAvg 0.528s\r\n\r\ntest: longdouble3=longdouble1+longdouble2 100000000 times\r\n1 0.250s 2 0.250s 3 0.250s 4 0.234s 5 0.250s\r\n6 0.360s 7 0.234s 8 0.250s 9 0.328s 10 0.250s\r\nAvg 0.266s\r\n\r\ntest: longdouble3=longdouble1-longdouble2 100000000 times\r\n1 0.297s 2 0.250s 3 0.313s 4 0.234s 5 0.281s\r\n6 0.250s 7 0.313s 8 0.265s 9 0.250s 10 0.282s\r\nAvg 0.273s\r\n\r\ntest: longdouble3=longdouble1*longdouble2 100000000 times\r\n1 0.250s 2 0.328s 3 0.281s 4 0.297s 5 0.281s\r\n6 0.281s 7 0.266s 8 0.297s 9 0.281s 10 0.235s\r\nAvg 0.280s\r\n\r\ntest: longdouble3=longdouble1\/longdouble2 100000000 times\r\n1 0.640s 2 0.735s 3 0.625s 4 0.640s 5 0.672s\r\n6 0.625s 7 0.641s 8 0.656s 9 0.656s 10 0.688s\r\nAvg 0.658s\r\n\r\n<\/pre>\n<p>\u8f83\u4e3a\u76f4\u89c2\u7684\u7edf\u8ba1\u8868\u683c\uff08\u65f6\u95f4\u5355\u4f4d\uff1a\u6beb\u79d2\uff09\uff1a<\/p>\n<table>\n<tbody>\n<tr>\n<th><\/th>\n<th>sizeof<\/th>\n<th>+<\/th>\n<th>&#8211;<\/th>\n<th>*<\/th>\n<th>\/<\/th>\n<th>%<\/th>\n<\/tr>\n<tr>\n<th>short<\/th>\n<td>2<\/td>\n<td>36<\/td>\n<td>52<\/td>\n<td>41<\/td>\n<td>347<\/td>\n<td>313<\/td>\n<\/tr>\n<tr>\n<th>long<\/th>\n<td>4<\/td>\n<td>39<\/td>\n<td>48<\/td>\n<td>36<\/td>\n<td>306<\/td>\n<td>319<\/td>\n<\/tr>\n<tr>\n<th>long long<\/th>\n<td>8<\/td>\n<td>39<\/td>\n<td>63<\/td>\n<td>39<\/td>\n<td>950<\/td>\n<td>972<\/td>\n<\/tr>\n<tr>\n<th>float<\/th>\n<td>4<\/td>\n<td>39<\/td>\n<td>39<\/td>\n<td>41<\/td>\n<td>253<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<th>double<\/th>\n<td>8<\/td>\n<td>36<\/td>\n<td>36<\/td>\n<td>42<\/td>\n<td>528<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<th>long double<\/th>\n<td>16<\/td>\n<td>266<\/td>\n<td>273<\/td>\n<td>280<\/td>\n<td>658<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7ed3\u8bba\uff1a<\/p>\n<li>short\u5e76\u4e0d\u4e00\u5b9a\u6bd4long\u66f4\u5feb\uff0c\u5982\u679c\u4e0d\u662f\u7a7a\u95f4\u4e0a\u7684\u9650\u5236\uff0c\u76f4\u63a5\u9009\u7528long\u5c31\u53ef\u4ee5\u3002<\/li>\n<li>long long\u5728\u9664\u6cd5\u548c\u53d6\u4f59\u8fd0\u7b97\u4e0a\u663e\u8457\u6162\u4e8elong\u3002<\/li>\n<li>double\u53ea\u6709\u5728\u9664\u6cd5\u4e0a\u624d\u663e\u8457\u6162\u4e8efloat\u3002<\/li>\n<li>long double\u5404\u79cd\u8fd0\u7b97\u90fd\u6bd4double\u6162\u3002<\/li>\n<li>\u6d6e\u70b9\u6570\u8ba1\u7b97(float\u3001double)\u548c\u6574\u6570\u8ba1\u7b97(short\u3001long)\u7684\u901f\u5ea6\u4e0d\u76f8\u4e0a\u4e0b\u3002<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u5bf9C\u8bed\u8a00\u4e2d\u5404\u79cd\u6570\u636e\u7c7b\u578b\u7684\u56db\u5219\u8fd0\u7b97\u901f\u5ea6\u8fdb\u884c\u4e86\u6d4b\u8bd5\u3002 \u64cd\u4f5c\u7cfb\u7edf\uff1aWindows 8.1 \u4e13\u4e1a\u7248 (64\u4f4d) \u7f16\u8bd1 &hellip; <a href=\"https:\/\/sqrt-1.me\/?p=107\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u5bf9C\u8bed\u8a00\u4e2d\u4e0d\u540c\u7c7b\u578b\u6570\u636e\u8ba1\u7b97\u901f\u5ea6\u7684\u6d4b\u8bd5\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[2],"tags":[],"class_list":["post-107","post","type-post","status-publish","format-standard","hentry","category-c-language"],"_links":{"self":[{"href":"https:\/\/sqrt-1.me\/index.php?rest_route=\/wp\/v2\/posts\/107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqrt-1.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqrt-1.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqrt-1.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqrt-1.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=107"}],"version-history":[{"count":8,"href":"https:\/\/sqrt-1.me\/index.php?rest_route=\/wp\/v2\/posts\/107\/revisions"}],"predecessor-version":[{"id":348,"href":"https:\/\/sqrt-1.me\/index.php?rest_route=\/wp\/v2\/posts\/107\/revisions\/348"}],"wp:attachment":[{"href":"https:\/\/sqrt-1.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqrt-1.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqrt-1.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}