{"id":8274,"date":"2014-04-09T00:36:24","date_gmt":"2014-04-08T23:36:24","guid":{"rendered":"http:\/\/www.itwriting.com\/blog\/?p=8274"},"modified":"2014-04-09T00:36:24","modified_gmt":"2014-04-08T23:36:24","slug":"a-quick-hands-on-with-native-code-compilation-for-net","status":"publish","type":"post","link":"https:\/\/www.itwriting.com\/blog\/8274-a-quick-hands-on-with-native-code-compilation-for-net.html","title":{"rendered":"A quick hands-on with native code compilation for .NET"},"content":{"rendered":"<p>I had a quick look at the <a href=\"http:\/\/msdn.microsoft.com\/en-US\/vstudio\/dotnetnative\" target=\"_blank\">.NET Native Preview<\/a>. I am interested to see what the benefits might be. Note that currently the preview only supports 64-bit Windows Store apps.<\/p>\n<p>Here is what is <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dn584397.aspx\" target=\"_blank\">promised<\/a>:<\/p>\n<blockquote><p>For users of your apps, .NET Native offers these advantages:<\/p>\n<ul>\n<li>Fast execution times<\/li>\n<li>Consistently speedy startup times<\/li>\n<li>Low deployment and update costs<\/li>\n<li>Optimized app memory usage<\/li>\n<\/ul>\n<\/blockquote>\n<p>I created a small C# app that counts prime numbers using a simple approach. I created it first as a Universal App that does not use .NET Native, and then as a second app that does use .NET Native.<\/p>\n<p><a href=\"http:\/\/www.itwriting.com\/blog\/wp-content\/uploads\/2014\/04\/image17.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" alt=\"image\" src=\"http:\/\/www.itwriting.com\/blog\/wp-content\/uploads\/2014\/04\/image_thumb17.png\" width=\"244\" height=\"173\" border=\"0\" \/><\/a><\/p>\n<p>My initial results are disappointing. The time taken to count prime numbers is similar in both apps.<\/p>\n<p><a href=\"http:\/\/www.itwriting.com\/blog\/wp-content\/uploads\/2014\/04\/image18.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" alt=\"image\" src=\"http:\/\/www.itwriting.com\/blog\/wp-content\/uploads\/2014\/04\/image_thumb18.png\" width=\"244\" height=\"188\" border=\"0\" \/><\/a><\/p>\n<p>As a further test, I added code that adds the prime numbers found to a ListView control using an async task. The idea was to\u00a0see if GUI interaction and multi-threading would be more\u00a0revealing than simply crunching numbers in a tight loop.\u00a0The apps takes much longer with this enabled, but again, there is nothing to choose between the two.<\/p>\n<p>Did I really succeed in compiling the app to native code? I think so. Here are the contents of the AppX folder for the standard .NET executable:<\/p>\n<p><a href=\"http:\/\/www.itwriting.com\/blog\/wp-content\/uploads\/2014\/04\/image19.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" alt=\"image\" src=\"http:\/\/www.itwriting.com\/blog\/wp-content\/uploads\/2014\/04\/image_thumb19.png\" width=\"404\" height=\"286\" border=\"0\" \/><\/a><\/p>\n<p>and here for the native compiled executable \u2013 note the additional DLLs:<\/p>\n<p><a href=\"http:\/\/www.itwriting.com\/blog\/wp-content\/uploads\/2014\/04\/image20.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;\" title=\"image\" alt=\"image\" src=\"http:\/\/www.itwriting.com\/blog\/wp-content\/uploads\/2014\/04\/image_thumb20.png\" width=\"404\" height=\"261\" border=\"0\" \/><\/a><\/p>\n<p>I am not actually surprised that there is no performance benefit in my example. JIT (just-in-time) compilation means that any .NET application is native code at runtime, though optimization might be different.<\/p>\n<p>I have ended up with a much larger app to deploy, though the relative difference would be less, I imagine, with an app that contains more code.<\/p>\n<p>I can also readily believe that start-up time will be better for a native compiled app, since there is no need for the JIT compiler. However my app is so small that this is not significant.<\/p>\n<p>My question though is what kind of app will benefit most from native compilation? I would be interested to see guidance on this.<\/p>\n<p>Of course it is also possible that later iterations of the technology will yield different results.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had a quick look at the .NET Native Preview. I am interested to see what the benefits might be. Note that currently the preview only supports 64-bit Windows Store apps. Here is what is promised: For users of your apps, .NET Native offers these advantages: Fast execution times Consistently speedy startup times Low deployment &hellip; <a href=\"https:\/\/www.itwriting.com\/blog\/8274-a-quick-hands-on-with-native-code-compilation-for-net.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">A quick hands-on with native code compilation for .NET<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,26,55,80,94,97],"tags":[104,586,996],"class_list":["post-8274","post","type-post","status-publish","format-standard","hentry","category-net","category-development","category-microsoft","category-software-development","category-visual-studio","category-windows","tag-net","tag-microsoft","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/8274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/comments?post=8274"}],"version-history":[{"count":0,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/8274\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/media?parent=8274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/categories?post=8274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/tags?post=8274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}