{"id":19,"date":"2021-12-05T10:25:59","date_gmt":"2021-12-05T16:25:59","guid":{"rendered":"https:\/\/aflyonthewall.page\/?p=19"},"modified":"2025-11-11T19:19:59","modified_gmt":"2025-11-12T01:19:59","slug":"tinkering-with-the-commodore-64-and-vice-speed-of-arithmetic-on-integer-variables","status":"publish","type":"post","link":"https:\/\/aflyonthewall.page\/index.php\/2021\/12\/05\/tinkering-with-the-commodore-64-and-vice-speed-of-arithmetic-on-integer-variables\/","title":{"rendered":"Speed of BASIC Arithmetic on a Commodore 64"},"content":{"rendered":"\n<p>I grew up with a C64. A relative gave it to me; at the time, it had started going out of fashion for AOL, Prodigy, and all things online. <\/p>\n\n\n\n<p>I learned to love programming because of it, and it started a lifetime of working with computing systems.<\/p>\n\n\n\n<p>I&#8217;ve recently rediscovered <a href=\"https:\/\/vice-emu.sourceforge.io\/\" data-type=\"URL\" data-id=\"https:\/\/vice-emu.sourceforge.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">VICE<\/a>. Not only are the C64 and C128 emulated, but the C64 with a <a href=\"https:\/\/www.c64-wiki.com\/wiki\/SuperCPU\" data-type=\"URL\" data-id=\"https:\/\/www.c64-wiki.com\/wiki\/SuperCPU\" target=\"_blank\" rel=\"noreferrer noopener\">Creative Micro Designs SuperCPU<\/a> is emulated as well.  I have access to all the things I wanted as a kid but couldn&#8217;t afford, on the computer I already have today on my desk.<\/p>\n\n\n\n<p>So I start up the the emulated C64 with SCPU, and lo and behold, it&#8217;s awesome. Programming with BASIC on this is on another level; much more comfortable than my memory of it.<\/p>\n\n\n\n<p>Today&#8217;s find: for some reason, doing arithmetic on integer variables is slower than doing arithmetic on the default floating point variable type.<\/p>\n\n\n\n<p>As an example:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aflyonthewall.page\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-05-10-14-53.png\" alt=\"\" class=\"wp-image-22\" width=\"480\" height=\"184\" srcset=\"https:\/\/aflyonthewall.page\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-05-10-14-53.png 948w, https:\/\/aflyonthewall.page\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-05-10-14-53-300x116.png 300w, https:\/\/aflyonthewall.page\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-05-10-14-53-768x296.png 768w, https:\/\/aflyonthewall.page\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-05-10-14-53-760x293.png 760w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><figcaption>Elasped time for performing addition 999 times with an Integer variable<\/figcaption><\/figure><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/aflyonthewall.page\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-05-10-15-39.png\" alt=\"\" class=\"wp-image-23\" width=\"478\" height=\"181\" srcset=\"https:\/\/aflyonthewall.page\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-05-10-15-39.png 967w, https:\/\/aflyonthewall.page\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-05-10-15-39-300x114.png 300w, https:\/\/aflyonthewall.page\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-05-10-15-39-768x292.png 768w, https:\/\/aflyonthewall.page\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-05-10-15-39-760x289.png 760w\" sizes=\"auto, (max-width: 478px) 100vw, 478px\" \/><figcaption>Elapsed time for performing the same addition with a default floating point variable<\/figcaption><\/figure><\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The difference is 3\/60th of a second, or it takes about 10.3% of the time longer to do this arithmetic on an integer variable than a floating point variable.<\/p>\n\n\n\n<p>Maybe the reason BASIC had these included was for memory savings more than speed. Maybe the floating point version is faster because the BASIC interpreter takes more time just decoding the code.<\/p>\n\n\n\n<p>Surprising to me either way, considering the complexity of performing floating point math on a 6502.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I grew up with a C64. A relative gave it to me; at the time, it had started going out of fashion for AOL, Prodigy, and all things online. I learned to love programming because of it, and it started a lifetime of working with computing systems. I&#8217;ve recently rediscovered VICE. Not only are the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-19","post","type-post","status-publish","format-standard","hentry","category-retrocomputing"],"_links":{"self":[{"href":"https:\/\/aflyonthewall.page\/index.php\/wp-json\/wp\/v2\/posts\/19","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aflyonthewall.page\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aflyonthewall.page\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aflyonthewall.page\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aflyonthewall.page\/index.php\/wp-json\/wp\/v2\/comments?post=19"}],"version-history":[{"count":16,"href":"https:\/\/aflyonthewall.page\/index.php\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":191,"href":"https:\/\/aflyonthewall.page\/index.php\/wp-json\/wp\/v2\/posts\/19\/revisions\/191"}],"wp:attachment":[{"href":"https:\/\/aflyonthewall.page\/index.php\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aflyonthewall.page\/index.php\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aflyonthewall.page\/index.php\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}