{"id":1189,"date":"2012-03-26T21:43:29","date_gmt":"2012-03-26T20:43:29","guid":{"rendered":"http:\/\/roboblog.fatal-fury.de\/?p=1189"},"modified":"2012-04-09T16:57:23","modified_gmt":"2012-04-09T15:57:23","slug":"faster-64bit-c-code-part1","status":"publish","type":"post","link":"http:\/\/roboblog.fatal-fury.de\/?p=1189","title":{"rendered":"Faster 64Bit C Code - Part1"},"content":{"rendered":"<p>Auf 64Bit Plattformen ist in der Regel ein Int 32Bit gro\u00df. Macht man damit Pointerarithmetik muss die 32Bit Zahl erst zu eine 64Bit zahl convertiert werden, bevor sie verrechnet wird. Pointer sind auf 64Bit Plattformen auch 64Bit gro\u00df.<\/p>\n<p>Durch den Einsatz von size_t statt int und ptrdiff_t statt int* l\u00e4sst sich das verhindern. Siehe <a href=\"http:\/\/www.viva64.com\/en\/a\/0050\/\">http:\/\/www.viva64.com\/en\/a\/0050\/<\/a><\/p>\n<p>Ich habe mit Valgrind mir die Anzahl der Instrktionen f\u00fcr die Testfunktion geben lassen und es stimmt. Es werden f\u00fcr dieses<br \/>\nBeispiel nur noch 5 statt 4 Instruktionen f\u00fcr ein Array Element ben\u00f6tigt.<\/p>\n<p>Hier mein Testprogramm:<\/p>\n<pre>\r\n<code>#include < iostream >\r\n#include < stdlib.h >\r\n\r\nvoid func(size_t arraySize, float array[] ) {\r\n  for (size_t i = 0; i < arraySize \/ 2; i++)\r\n  {\r\n    float value = array[i];\r\n    array[i] = array[arraySize - i - 1];\r\n    array[arraySize - i - 1] = value;\r\n  }\r\n}\r\n\r\nint main(int argc, char **argv) {\r\n        unsigned int n = atoi(argv[1]);\r\n        std::cout << n << std::endl;\r\n        float *arr = new float[n];\r\n\r\n        func(n, arr);\r\n\r\n        std::cout << \"ausgabe \" << arr[0] << std::endl;\r\n        delete[] arr;\r\n        return 0;\r\n}\r\n\r\ng++ -O2  -Wall object.cpp\r\nvalgrind --tool=callgrind   --collect-systime=yes --callgrind-out-file=unsignedint.out .\/a.out 100000000\r\ncallgrind_annotate unsignedint.out |grep func\r\n\r\narray           Instruction count\r\nlenght     unsigned int        size_t\r\n\r\n1*10^8    500,000,007         400,000,007 \r\n1*10^7     50,000,007          40,000,007\r\n1*10^6      5,000,007           4,000,007  \r\n1*10^5        500,007             400,007\r\n1*10^4         50,007              40,007\r\n1*10^3          5,007               4,007<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Auf 64Bit Plattformen ist in der Regel ein Int 32Bit gro\u00df. Macht man damit Pointerarithmetik muss die 32Bit Zahl erst zu eine 64Bit zahl convertiert werden, bevor sie verrechnet wird. Pointer sind auf 64Bit Plattformen auch 64Bit gro\u00df. Durch den Einsatz von size_t statt int und ptrdiff_t statt int* l\u00e4sst sich das verhindern. Siehe http:\/\/www.viva64.com\/en\/a\/0050\/ [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[14,17,31,18],"class_list":["post-1189","post","type-post","status-publish","format-standard","hentry","category-allgemein","tag-c","tag-cpp","tag-faster-code","tag-linux"],"_links":{"self":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/1189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1189"}],"version-history":[{"count":9,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/1189\/revisions"}],"predecessor-version":[{"id":1331,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/1189\/revisions\/1331"}],"wp:attachment":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1189"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}