{"id":8,"date":"2004-08-31T23:52:03","date_gmt":"2004-08-31T21:52:03","guid":{"rendered":"http:\/\/ken.friislarsen.net\/blog\/?p=8"},"modified":"2004-08-31T23:52:03","modified_gmt":"2004-08-31T21:52:03","slug":"a-hand-full-of-queens","status":"publish","type":"post","link":"http:\/\/ken.friislarsen.net\/blog\/2004\/08\/31\/a-hand-full-of-queens\/","title":{"rendered":"A hand full of Queens"},"content":{"rendered":"<p>Or: <b>SML\/Moscow ML is faster than C++\/GCC<\/b><\/p>\n<p>Inspired by a remark by <a href=\"http:\/\/www.dina.dk\/~sestoft\">Peter<\/a> about the abysmal performance of exceptions on the .NET platform.  I decided to check it for myself with a micro-benchmark. I also decided to check the performance of C++ exceptions, just for the fun of it.<\/p>\n<p>The micro-benchmark is to find a solution to the N-queen problem using backtracking, with exceptions used as backtracking. I tested four different languages (SML, O&#8217;Caml, C#, and C++) and five different language implementations (<a href=\"http:\/\/mlton.org\">MLton<\/a>, <a href=\"http:\/\/www.dina.dk\/~sestoft\/mosml.html\">Moscow ML<\/a>, <a href=\"http:\/\/caml.inria.fr\/ocaml\">O&#8217;Caml<\/a>, <a href=\"http:\/\/mono-project.com\">Mono<\/a>, and <a href=\"http:\/\/gcc.gnu.org\/\">GCC<\/a>). The results are a bit surprising, and definately deserves further investigation. The graph below shows the running times for the five different executables:<\/p>\n<p align=\"center\"><a href=\"http:\/\/ken.friislarsen.net\/blog\/images\/queens-graph.png\"><img decoding=\"async\" src=\"http:\/\/ken.friislarsen.net\/blog\/images\/queens-graph-small.png\" alt=\"Graph showing running times for the different executables\"\/><\/a><\/p>\n<p>From the graph we see that O&#8217;Caml and MLton are way faster than the rest (and O&#8217;Caml has a small edge compared to MLton), Moscow ML is faster than Mono, and my C++ program is slow as a slug. I&#8217;ve tried various small tweaks to make the C++ version faster, but nothing really helps. For instance, at first we might notice that there are a tiny algorithmic difference between the C++ version and the other versions, namely the order in which a new position is compared with the already determined positions. But changing this order have no real effect (I&#8217;ve tried to change C++ program in various ways, and I tried to change the other programs). Still, the C++ performance is so bad that it looks suspicious. I&#8217;m open to suggestions for how to improve the C++ program.<\/p>\n<p>Now I just have to test the SML version with the MLKit and SML\/NJ, test the C# version with Microsoft&#8217;s runtime, test the C++ version with Visual C++ and Intel&#8217;s C++ compiler, and make a Java version of the benchmark and test it with &#8230;  Any volunteers?\n<\/p>\n<p>The programs used in the benchmark are here: <a href=\"http:\/\/ken.friislarsen.net\/blog\/images\/queens.sml\">queens.sml<\/a>, <a href=\"http:\/\/ken.friislarsen.net\/blog\/images\/queens.ml\">queens.ml<\/a>, <a href=\"http:\/\/ken.friislarsen.net\/blog\/images\/queens.cs\">queens.cs<\/a> (ran <code>mono<\/code> with option <code>--optimize=all<\/code>) , and <a href=\"http:\/\/ken.friislarsen.net\/blog\/images\/queens.cpp\">queens.cpp<\/a> (compiled with option <code>-O3<\/code>).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Or: SML\/Moscow ML is faster than C++\/GCC Inspired by a remark by Peter about the abysmal performance of exceptions on the .NET platform. I decided to check it for myself with a micro-benchmark. I also decided to check the performance of C++ exceptions, just for the fun of it. The micro-benchmark is to find a <a class=\"read-more\" href=\"http:\/\/ken.friislarsen.net\/blog\/2004\/08\/31\/a-hand-full-of-queens\/\">[&hellip;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,4,10,7],"tags":[],"class_list":["post-8","post","type-post","status-publish","format-standard","hentry","category-c","category-coding","category-ocaml","category-sml"],"_links":{"self":[{"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/posts\/8","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":0,"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/posts\/8\/revisions"}],"wp:attachment":[{"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/media?parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/categories?post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ken.friislarsen.net\/blog\/wp-json\/wp\/v2\/tags?post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}