<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>take a bit, get a byte &#187; mono</title>
	<atom:link href="http://spouliot.wordpress.com/category/mono/feed/" rel="self" type="application/rss+xml" />
	<link>http://spouliot.wordpress.com</link>
	<description>a new world monkey</description>
	<lastBuildDate>Thu, 23 May 2013 13:17:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='spouliot.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>take a bit, get a byte &#187; mono</title>
		<link>http://spouliot.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://spouliot.wordpress.com/osd.xml" title="take a bit, get a byte" />
	<atom:link rel='hub' href='http://spouliot.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Graphics vs Resolution Independance</title>
		<link>http://spouliot.wordpress.com/2012/12/12/graphics-vs-resolution-independance/</link>
		<comments>http://spouliot.wordpress.com/2012/12/12/graphics-vs-resolution-independance/#comments</comments>
		<pubDate>Wed, 12 Dec 2012 12:51:08 +0000</pubDate>
		<dc:creator>spouliot</dc:creator>
				<category><![CDATA[mono]]></category>
		<category><![CDATA[monomac]]></category>
		<category><![CDATA[monotouch]]></category>
		<category><![CDATA[xamarin]]></category>

		<guid isPermaLink="false">http://spouliot.wordpress.com/?p=870</guid>
		<description><![CDATA[I love my retina iPad (and retina iPod Touch, but no retina MacBook yet) and I hate seeing applications that does not support them, it&#8217;s wasting pixels. However I&#8217;m not exactly an artist &#8211; as seen in yesterday&#8217;s screenshots. In &#8230; <a href="http://spouliot.wordpress.com/2012/12/12/graphics-vs-resolution-independance/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=870&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I love my retina iPad (and retina iPod Touch, but no retina MacBook <em>yet</em>) and I hate seeing applications that does not support them, it&#8217;s wasting pixels. However I&#8217;m not exactly an artist &#8211; as seen in <a href="http://spouliot.wordpress.com/2012/12/11/airplay-vs-ios-api/" title="AirPlay vs iOS API">yesterday&#8217;s</a> screenshots.</p>
<p>In that particular case I think the &#8220;tv&#8221; text makes a <em>great</em> icon &#8211; even if it may be a bit too localized (is AppleTV translated to something else anywhere ?). Anyway it&#8217;s clear to me that using a bit of code, like below, to generate images is a good way to support any number of screen resolution / density for mobile applications.</p>
<pre class="brush: csharp; title: ; notranslate">
	static UIImage GetIcon ()
	{
		float size = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 
			55f : 43f;
		UIGraphics.BeginImageContextWithOptions (new SizeF (size, size), false, 0.0f);
		using (var c = UIGraphics.GetCurrentContext ()) {
			c.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);
			c.SetStrokeColor (1.0f, 1.0f, 1.0f, 1.0f);
			UIFont font = UIFont.BoldSystemFontOfSize (size - 8);
			using (var s = new NSString (&quot;tv&quot;))
				s.DrawString (new PointF (7.5f, 0.0f), font);
		}
		UIImage img = UIGraphics.GetImageFromCurrentImageContext ();
		UIGraphics.EndImageContext ();
		return img;
	}
</pre>
<p>This technique was refined by the folks at PixelCut, creator of <a href="http://www.paintcodeapp.com">PaintCodeApp</a>, which let you create CoreGraphics-API compatible source code (either in Objective C or C#) from images you draw (instead of type).</p>
<p>This application is <strong>fantastic</strong> unless you realize you&#8217;re lacking a minimum of artistic talent <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  Thanksfully other people have this talent, like the folks doing <a href="http://fortawesome.github.com/Font-Awesome/">FontAwesome</a> which offers a lot of nice, useful icons in several formats.</p>
<p>One such format is SVG, specifically <a href="http://www.w3.org/TR/SVG/paths.html#PathElement">SVG paths</a>, which is something we had to implement in <a href="http://www.go-mono.com/moonlight/">Moonlight</a> (that seems a lifetime ago). Translating this C++ code into a C# library was pretty easy. In fact it was a lot easier than doing the original code &#8211; parts of the spec are not trivial, e.g. you can find quite a few SVG (path) library or <a href="http://yepher.com/svg2ios.html">converters</a> that simply ignore arcs (and even other constructs).</p>
<p>Next, using this new <a href="https://github.com/spouliot/svgpath2code/tree/master/Poupou.SvgPathConverter">library</a> I created a small (less than 100 lines) tool to <a href="https://github.com/spouliot/svgpath2code/blob/master/convert-font-awesome/convert-font-awesome.cs">convert</a> all symbols into a (rather big, around 15k lines) C# source file containing all SVG paths, each in it&#8217;s own method. That generated file was then used in a <a href="http://xamarin.com/monotouch">MonoTouch</a> <a href="https://github.com/spouliot/svgpath2code/tree/master/AwesomeDemo">sample app</a> (again less than 100 lines) to show them in a table view (using <a href="https://github.com/migueldeicaza/MonoTouch.Dialog/">MonoTouch.Dialog</a>).</p>
<p><a href="http://spouliot.wordpress.com/2012/12/12/graphics-vs-resolution-independance/awesome-app/" rel="attachment wp-att-887"><img src="http://spouliot.files.wordpress.com/2012/12/awesome-app.png?w=640" alt="awesome-app"   class="aligncenter size-full wp-image-887" /></a></p>
<p>Now this is not <em>really</em> new, <a href="http://spouliot.wordpress.com/2011/09/28/unit-testing-and-monotouch/" title="Unit testing and MonoTouch ?">Touch.Unit</a> has been <a href="https://github.com/spouliot/Touch.Unit/blob/master/NUnitLite/TouchRunner/TouchViewController.cs#L265">using</a> this for a while. New or not, consider this as my xmas gift to other art-challenged developers in needs of nice, scalable icons for their mobile apps <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Also if you&#8217;re not using C# or CoreGraphics then you might want to contribute other backends. The library (and command-line tool) are made to be extensible &#8211; but I do not have immediate needs (or plans) for other language / toolkit at the moment.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spouliot.wordpress.com/870/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spouliot.wordpress.com/870/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=870&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spouliot.wordpress.com/2012/12/12/graphics-vs-resolution-independance/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dcbd727a1d3fe8eebba8b53e4d9ea4cf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spouliot</media:title>
		</media:content>

		<media:content url="http://spouliot.files.wordpress.com/2012/12/awesome-app.png" medium="image">
			<media:title type="html">awesome-app</media:title>
		</media:content>
	</item>
		<item>
		<title>AirPlay vs iOS API</title>
		<link>http://spouliot.wordpress.com/2012/12/11/airplay-vs-ios-api/</link>
		<comments>http://spouliot.wordpress.com/2012/12/11/airplay-vs-ios-api/#comments</comments>
		<pubDate>Tue, 11 Dec 2012 13:06:35 +0000</pubDate>
		<dc:creator>spouliot</dc:creator>
				<category><![CDATA[airplay]]></category>
		<category><![CDATA[appletv]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[monotouch]]></category>
		<category><![CDATA[xamarin]]></category>

		<guid isPermaLink="false">http://spouliot.wordpress.com/?p=844</guid>
		<description><![CDATA[This post should not be a big surprise. As you might have guessed I had other ideas with my AppleTV. I think there&#8217;s a large, untapped potential in the AppleTV to be used with/from other devices. Collaboration, visualization and of &#8230; <a href="http://spouliot.wordpress.com/2012/12/11/airplay-vs-ios-api/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=844&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This post should not be a big surprise. As you might have <a href="http://spouliot.wordpress.com/2012/12/10/airplay-vs-large-digital-frame/" title="AirPlay vs Large Digital Frame">guessed</a> I had other ideas with my AppleTV.</p>
<p>I think there&#8217;s a large, untapped potential in the AppleTV to be used with/from other devices. Collaboration, visualization and of course gaming (think of the <strong>Wii U</strong>) comes to mind. Sadly several pieces are missing for this to become reality <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  Let&#8217;s try to add one of them&#8230;</p>
<p>If you played the iOS API for AirPlay you already know it does not really support pictures, i.e. what the (Apple supplied) Photo.app does is not available to developers. In particular:</p>
<ul>
<li>The device selector (available thru <a href="http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPVolumeView_Class/Reference/Reference.html">MPVolumeView</a>) shows <em>every</em> AirPlay devices, including AirExpress for speakers. Photo.app <em>somehow</em> filters them since they can&#8217;t show pictures;</li>
<li>It does not allow you to provide what&#8217;s to be shown on the AppleTV, that must be done with the <a href="http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPVolumeView_Class/Reference/Reference.html">MPVolumeView</a> which is not picture friendly;</li>
<li>The closest you can get is screen mirroring (only on recent iOS devices) and that&#8217;s not quite the same since your (iOS device) screen is not available to other uses.</li>
</ul>
<p>Note: I know private API exists to do this but, like the jailbreaking, I do not want my app to depend on them.</p>
<p>Like I showed <a href="http://spouliot.wordpress.com/2012/12/10/airplay-vs-large-digital-frame/" title="AirPlay vs Large Digital Frame">before</a> using .NET to show pictures to an AppleTV is quite simple. What&#8217;s needed is a UI for this&#8230;</p>
<p>And here&#8217;s come <a href="https://github.com/spouliot/airplay/tree/master/Poupou.AirPlay">Poupou.AirPlay</a> assembly that provides browsing AirPlay devices and sending pictures to them. It works on any iPad and iPhone/iPod Touch (at least everything running iOS5, I did not test earlier versions &#8211; feedback appreciated). </p>
<p>To select a AirPlay device the code uses <a href="http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIActivity_Class/Reference/Reference.html">UIActivity</a>, available in iOS 6 (and later). </p>
<p align="center">
<a href="http://spouliot.wordpress.com/2012/12/11/airplay-vs-ios-api/airpic-iphone-60/" rel="attachment wp-att-853"><img src="http://spouliot.files.wordpress.com/2012/12/airpic-iphone-60.png?w=640" alt="airpic-iphone-60"   class="aligncenter size-full wp-image-853" />iOS 6.0 screenshot</a>
</p>
<p>But it&#8217;s easy to support earlier iOS releases with a bit of extra code. The <a href="https://github.com/spouliot/airplay/tree/master/airpic-ios">sample</a> application shows you how to do that.</p>
<p align="center">
<a href="http://spouliot.wordpress.com/2012/12/11/airplay-vs-ios-api/airpic-iphone-51/" rel="attachment wp-att-852"><img src="http://spouliot.files.wordpress.com/2012/12/airpic-iphone-51.png?w=640" alt="airpic-iphone-51"   class="aligncenter size-full wp-image-852" />iOS 5.1 screenshot</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spouliot.wordpress.com/844/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spouliot.wordpress.com/844/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=844&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spouliot.wordpress.com/2012/12/11/airplay-vs-ios-api/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dcbd727a1d3fe8eebba8b53e4d9ea4cf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spouliot</media:title>
		</media:content>

		<media:content url="http://spouliot.files.wordpress.com/2012/12/airpic-iphone-60.png" medium="image">
			<media:title type="html">airpic-iphone-60</media:title>
		</media:content>

		<media:content url="http://spouliot.files.wordpress.com/2012/12/airpic-iphone-51.png" medium="image">
			<media:title type="html">airpic-iphone-51</media:title>
		</media:content>
	</item>
		<item>
		<title>AirPlay vs Large Digital Frame</title>
		<link>http://spouliot.wordpress.com/2012/12/10/airplay-vs-large-digital-frame/</link>
		<comments>http://spouliot.wordpress.com/2012/12/10/airplay-vs-large-digital-frame/#comments</comments>
		<pubDate>Mon, 10 Dec 2012 13:17:28 +0000</pubDate>
		<dc:creator>spouliot</dc:creator>
				<category><![CDATA[airplay]]></category>
		<category><![CDATA[appletv]]></category>
		<category><![CDATA[mono]]></category>

		<guid isPermaLink="false">http://spouliot.wordpress.com/?p=819</guid>
		<description><![CDATA[We (as a family) have been looking for a large digital frame. My wife takes a lot of pictures (mostly kids and vacations) and showing them was always&#8230; less than optimal. We have a few, small 7-8 inches, digital frames &#8230; <a href="http://spouliot.wordpress.com/2012/12/10/airplay-vs-large-digital-frame/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=819&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>We (as a family) have been looking for a large digital frame. My wife takes a lot of pictures (mostly kids and vacations) and showing them was always&#8230; less than optimal.</p>
<ul>
<li>We have a few, small 7-8 inches, digital frames in the house &#8211; but we do not update them very often. Copying files around SD cards is just not fun enough;</li>
<li>The frames have a lot of options but we can never get the pictures to be shown long enough for our taste. That would be closer to 10 minutes and definitively <strong>not</strong> a 30 seconds slideshow;</li>
</li>
<li>The most common alternatives are to show pictures on the TV (we still have to get the pictures there) or sit in front of the computer (no file copying but not confortable for many people). We don&#8217;t do that unless we have friends or family visiting us;
</li>
</ul>
<p>So we wanted something larger with the <em>right</em> options &#8211; the kind of <strong>set and forget</strong>.</p>
<p>It turns out there are <strong>not</strong> many large digital frames out there. Most of them are using computer monitors with additonal hardware, sometime an (jailbroken) AppleTV. The biggest addition, to the common hardware, is the price markup on them.</p>
<p>Now in a totally, until recently, unrelated subject I&#8217;ve been a fan of the AppleTV for a while. However the sad truth is I don&#8217;t use my AppleTV. Why ? I can&#8217;t (yet?) create apps for it and bandwidth caps, which are almost universal in Canada, makes Netflix less attractive (and I have a dozen Netflix compatible devices anyway).</p>
<p>Does a large (e.g. 23 inch) monitor and an AppleTV makes everything fine ? Not quite.</p>
<ul>
<li>We do not want to move pictures (to the cloud or a device). If it takes extra steps then it won&#8217;t be done regularly enough to make it useful. The files are already in the computer/network drives;</li>
<li>We want the picture to be shown for more than a few seconds. The only <strong>right</strong> predetermined time is the one we decide.</li>
</ul>
<p>The AppleTV itself does not do that and, for various reasons, I did not want to jailbreak it. Thanksfully the <a href="http://nto.github.com/AirPlay.html" target="_blank">AirPlay protocol</a> was reverse engineered so it is possible to send pictures from a computer to an AppleTV. The device was not bought with this in mind, nor did I look for the AirPlay protocol only for this, but it turned out really easy (less than 100 C# lines) to make it work just like we wanted, which is:</p>
<ul>
<li>Scan a directory (and subdirectories) for pictures;</li>
<li>Shows pictures randomly &#8211; but never twice before starting again (by re-scaning the directories);</li>
<li>Send pictures to the AppleTV and wait for X seconds before showing the next one, i.e. the program, not the device, control the delay between pictures.</li>
</ul>
<p>Curious ? it&#8217;s in <a href="https://github.com/spouliot/airplay">github</a> <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spouliot.wordpress.com/819/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spouliot.wordpress.com/819/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=819&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spouliot.wordpress.com/2012/12/10/airplay-vs-large-digital-frame/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dcbd727a1d3fe8eebba8b53e4d9ea4cf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spouliot</media:title>
		</media:content>
	</item>
		<item>
		<title>Touch.Unit vs NUnitLite 0.7</title>
		<link>http://spouliot.wordpress.com/2012/05/16/touch-unit-vs-nunitlite-0-7/</link>
		<comments>http://spouliot.wordpress.com/2012/05/16/touch-unit-vs-nunitlite-0-7/#comments</comments>
		<pubDate>Wed, 16 May 2012 14:46:51 +0000</pubDate>
		<dc:creator>spouliot</dc:creator>
				<category><![CDATA[mono]]></category>
		<category><![CDATA[monotouch]]></category>
		<category><![CDATA[touch.unit]]></category>
		<category><![CDATA[xamarin]]></category>

		<guid isPermaLink="false">http://spouliot.wordpress.com/?p=810</guid>
		<description><![CDATA[Last week Charlie Poole released NUnitLite 0.7. This new release greatly reduce the feature gap between the older 0.6 release and the upcoming NUnit 3. I know people will rejoice having Assert.AreEqual(x,y) back as it is simpler than the Assert.That &#8230; <a href="http://spouliot.wordpress.com/2012/05/16/touch-unit-vs-nunitlite-0-7/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=810&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Last week <a href="http://nunit.net/blogs/?p=138">Charlie Poole</a> released <a href="https://launchpad.net/nunitlite/0.7/0.7">NUnitLite 0.7</a>. This new release greatly reduce the feature gap between the older 0.6 release and the upcoming <a href="https://launchpad.net/nunit-3.0/">NUnit 3</a>.</p>
<p>I know people will rejoice having <code>Assert.AreEqual(x,y)</code> back as it is simpler than the <code>Assert.That (x, Is.EqualTo (y))</code> syntax. Personally I&#8217;m more happy about <code>Assert.Throw</code> as I really like this one over the <code>[ExpectedException]</code> attribute. There&#8217;s a lot of <a href="https://launchpad.net/nunitlite/+milestone/0.7">new features / attributes</a>, many I never used (since the Mono-shipped version of NUnit did not have them), that should prove useful.</p>
<p>At this stage the only missing piece, IMHO (but shared with others too), is the lack of async testing &#8211; which I grown fond of during <a href="http://github.com/mono/moon">Moonlight</a>&#8216;s development.</p>
<p>Anyway this post is to announce that <a href="http://spouliot.wordpress.com/2011/09/28/unit-testing-and-monotouch/" title="Unit testing and MonoTouch ?">Touch.Unit</a> was updated to use this new 0.7 version of NUnitLite. Existing (old) features should be working fine (MonoTouch bots seems quite happy with it) but I have not yet used (tested ?) most of the new features. If you find anything wrong please fill a <a href="http://bugzilla.xamarin.com">bug report</a> !</p>
<p><strong>Availability:</strong> The next version of <a href="http://ios.xamarin.com">MonoTouch 5.3.x</a> will provide the updated Touch.Unit runner but if you can&#8217;t wait (or update) then pull the update from <a href="https://github.com/spouliot/Touch.Unit">github</a> and &#8220;test&#8221; it away <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spouliot.wordpress.com/810/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spouliot.wordpress.com/810/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=810&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spouliot.wordpress.com/2012/05/16/touch-unit-vs-nunitlite-0-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dcbd727a1d3fe8eebba8b53e4d9ea4cf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spouliot</media:title>
		</media:content>
	</item>
		<item>
		<title>Linker vs Bindings and IsDirectBinding</title>
		<link>http://spouliot.wordpress.com/2012/05/07/linker-vs-bindings-and-isdirectbinding/</link>
		<comments>http://spouliot.wordpress.com/2012/05/07/linker-vs-bindings-and-isdirectbinding/#comments</comments>
		<pubDate>Mon, 07 May 2012 12:25:53 +0000</pubDate>
		<dc:creator>spouliot</dc:creator>
				<category><![CDATA[linker]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[monotouch]]></category>
		<category><![CDATA[xamarin]]></category>

		<guid isPermaLink="false">http://spouliot.wordpress.com/?p=640</guid>
		<description><![CDATA[If you looked at my previous entries related to the linker and bindings: NewRefcount, UI thread checks, Runtime.Arch or at MonoTouch&#8216;s generated bindings source code then you likely noticed another common pattern, e.g. The use of IsDirectBinding (line #6) is &#8230; <a href="http://spouliot.wordpress.com/2012/05/07/linker-vs-bindings-and-isdirectbinding/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=640&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>If you looked at my previous entries related to the linker and bindings: <a href="http://spouliot.wordpress.com/2012/03/05/linker-vs-bindings-and-newrefcount/" title="Linker vs Bindings and NewRefcount">NewRefcount</a>, <a href="http://spouliot.wordpress.com/2012/03/02/linker-vs-bindings-and-ui-thread-checks/" title="Linker vs Bindings and UI Thread Checks">UI thread checks</a>, <a href="http://spouliot.wordpress.com/2012/02/29/linker-vs-bindings-and-runtime-arch/" title="Linker vs Bindings and Runtime.Arch">Runtime.Arch</a> or at <a href="http://ios.xamarin.com">MonoTouch</a>&#8216;s generated bindings source code then you likely noticed another common pattern, e.g.</p>
<pre class="brush: csharp; title: ; notranslate">
	[Export (&quot;sizeToFit&quot;)]
	[CompilerGenerated]
	public virtual void SizeToFit ()
	{
		global::MonoTouch.UIKit.UIApplication.EnsureUIThread ();
		if (IsDirectBinding) {
			Messaging.void_objc_msgSend (this.Handle, selSizeToFit);
		} else {
			Messaging.void_objc_msgSendSuper (this.SuperHandle, selSizeToFit);
		}
	}
</pre>
<p>The use of <code>IsDirectBinding</code> (line #6) is a bit less common in third party bindings, unless the <code>-e</code> option was used with <code>btouch</code> to allow types to <em>safely</em> inherit from your bindings. The fact that such an option exists is a sign that we&#8217;d like to get rid of this condition when it&#8217;s not required.</p>
<p>If we knew that a type is <strong>never</strong> subclassed then we could remove the <code>IsDirectBinding</code> (line #6)  as its value would be constant, <code>true</code>, and that would also allow the removal of the false branch (line #9). </p>
<p>Along with some <a href="http://spouliot.wordpress.com/2012/03/02/linker-vs-bindings-and-ui-thread-checks/" title="Linker vs Bindings and UI Thread Checks">previous</a> optimizations that can remove <code>[CompilerGenerated]</code> (line #2) and <code>EnsureUIThread</code> (line #5), we would end up with a smaller, branchless method that simply calls the right selector, like this:</p>
<pre class="brush: csharp; title: ; notranslate">
	[Export (&quot;sizeToFit&quot;)]
	public virtual void SizeToFit ()
	{
		Messaging.void_objc_msgSend (this.Handle, selSizeToFit);
	}
</pre>
<p>Now that&#8217;s something the linker can find out since it must analyze the application&#8217;s code. Furthermore it also knows, since runtime code generation is impossible on iOS, that the application cannot be extended, unless it&#8217;s re-compiled (and re-linked). That&#8217;s turning a disadvantage into an advantage! and, starting with <a href="http://docs.xamarin.com/ios/releases/MonoTouch_5/MonoTouch_5.3#MonoTouch_5.3.3">MonoTouch 5.3.3</a>, the <a href="http://docs.xamarin.com/ios/advanced_topics/linker">linker</a> gives you this (small) consolation <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>This optimization saves <strong>22 kb</strong> on a release build of <a href="http://tirania.org/tweetstation/">TweetStation</a> but, like most other linker-bindings changes, the real goal was <strong>not</strong> to save space (it&#8217;s still nice) but to reduce the number of conditions and branching in the code to allow faster execution.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spouliot.wordpress.com/640/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spouliot.wordpress.com/640/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=640&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spouliot.wordpress.com/2012/05/07/linker-vs-bindings-and-isdirectbinding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dcbd727a1d3fe8eebba8b53e4d9ea4cf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spouliot</media:title>
		</media:content>
	</item>
		<item>
		<title>Managed Crypto vs CommonCrypto : Deciphering results</title>
		<link>http://spouliot.wordpress.com/2012/05/02/managed-crypto-vs-commoncrypto-deciphering-results/</link>
		<comments>http://spouliot.wordpress.com/2012/05/02/managed-crypto-vs-commoncrypto-deciphering-results/#comments</comments>
		<pubDate>Wed, 02 May 2012 12:15:23 +0000</pubDate>
		<dc:creator>spouliot</dc:creator>
				<category><![CDATA[crimson]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[monotouch]]></category>
		<category><![CDATA[xamarin]]></category>

		<guid isPermaLink="false">http://spouliot.wordpress.com/?p=596</guid>
		<description><![CDATA[After the hash algorithms the next part of MonoTouch&#8216;s switch to CommonCrypto covers the symmetric ciphers, commonly referred to CommonCryptor. This includes: DESCryptoServiceProvider, TripleDESCryptoServiceProvider, RC2CryptoServiceProvider and parts of RijndaelManaged inside mscorlib.dll; ARC4Managed inside Mono.Security.dll; and AESManaged inside System.Core.dll Those are &#8230; <a href="http://spouliot.wordpress.com/2012/05/02/managed-crypto-vs-commoncrypto-deciphering-results/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=596&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>After the <a href="http://spouliot.wordpress.com/2012/05/01/managed-crypto-vs-commoncrypto-digesting-results/" title="Managed Crypto vs CommonCrypto : Digesting results">hash algorithms</a> the next part of <a href="http://ios.xamarin.com">MonoTouch</a>&#8216;s <a href="http://spouliot.wordpress.com/2012/04/30/managed-crypto-vs-commoncrypto/" title="Managed Crypto vs CommonCrypto">switch to CommonCrypto</a> covers the symmetric ciphers, commonly referred to <a href="http://www.opensource.apple.com/source/CommonCrypto/CommonCrypto-36064/CommonCrypto/CommonCryptor.h" target="_blank">CommonCryptor</a>. This includes:</p>
<ul>
<li><code><b>DES</b>CryptoServiceProvider</code>, <code><b>TripleDES</b>CryptoServiceProvider</code>, <code><b>RC2</b>CryptoServiceProvider</code> and <em>parts of</em> <code><b>Rijndael</b>Managed</code> inside <code>mscorlib.dll</code>;</li>
<li><code>A<b>RC4</b>Managed</code> inside <code>Mono.Security.dll</code>; and</li>
<li><code><b>AES</b>Managed</code> inside <code>System.Core.dll</code>
</ul>
<p>Those are all the <strong>symmetric</strong> algorithms that <a href="http://www.mono-project.com">Mono</a> provides (using managed code). Now they will all, for MonoTouch, be native except for the non-AES parts of Rijndael, i.e. when its block size is not the default 128 bits.</p>
<p>This time <strong>hardware acceleration</strong> is easier to detect as we can compare AES <a href="http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29">Electronic Codebook (ECB) mode</a> with AES <a href="http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29">Cipher Block Chaining (CBC) mode</a> &#8211; the later <a href="http://opensource.apple.com/source/CommonCrypto/CommonCrypto-36064/Source/GladmanAES/ccNewGladman.c">documented</a> to be accelerated. In software the most <em>basic</em> mode is ECB and the other modes are built on top of it. So ECB is <em>generally</em> a bit faster than CBC. If CBC turns out to be faster then it was either further optimized (small margin) or hardware accelerated (large margin).</p>
<p><a href="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-27-at-8-18-45-pm.png"><img src="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-27-at-8-18-45-pm.png?w=640" alt="" title="ECB versus CBC"   class="aligncenter size-full wp-image-731" /></a></p>
<p>The above graphics, made from the iPad 3 results, shows the performance (MB/s) on the vertical scale versus the buffer size (bytes) on the horizontal. Unlike the <a href="http://spouliot.wordpress.com/2012/05/01/managed-crypto-vs-commoncrypto-digesting-results/" title="Managed Crypto vs CommonCrypto : Digesting results">digest results</a> it&#8217;s hard to suspect anything other than hardware acceleration for such a drastic difference.</p>
<p>The next graphics compares the performance of the native/hardware implementations (of CommonCrypto) versus the managed implementations (of Mono). Values are the average, in MB/s, of all my devices. You&#8217;ll see that using older algorithms, like DES or TripleDES, is not the way to better performance, managed or native.</p>
<p><a href="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-27-at-8-47-03-pm.png"><img src="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-27-at-8-47-03-pm.png?w=640" alt="" title="Native vs Managed Performance"   class="aligncenter size-full wp-image-735" /></a></p>
<p><strong>Wait! where&#8217;s the 35.4x performance increase ?</strong></p>
<p>Uho, the AES results looks more like <strong>10x</strong> than <strong>35x</strong>, right ? That&#8217;s (a bit) because I used the average values of my devices and (mostly) because I did not use the <strong>magic tricks</strong>. IMO that gives a more honest picture &#8211; at least as much as benchmark can be <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>But, as promised, here are the exact incantations and sacrifices required to get up to <strong>35x</strong> increase. You&#8217;ll need three things:</p>
<p>1. An iPad 1st generation. It simply has the best performance &#8211; well over the iPad3 at <strong>18.8x</strong> and iPod4 at <strong>25.2x</strong> (see graphics below). It&#8217;s large and surprising variation. Yet all results are better than the non-magical <strong>10x</strong> average;</p>
<p>2. Your device needs to run on <strong>AC power</strong>. That will give more juice to the crypto processor &#8211; roughly doubling its performance. Power management, under battery, does not allow this level of performance. That&#8217;s <em>part of</em> the <strong>sacrifice</strong> required to get the maximum performance;</p>
<p>3. Use the optimal buffer size (again) but this time we&#8217;re talking about <strong>huge</strong> buffers. In case you did not notice them, on the ECB/CBC graphic above, you will need 512KB to get the maximum throughput (<strong>86.9 MB/s</strong> on iPad1). If you drop the buffers to 256KB you lose more than 3 MB/s. Drop them to 128KB and you&#8217;re down to 68.1 MB/s. Drop to 16 kb (the optimal size for battery operation) and you&#8217;ll only get 44.1 MB/s &#8211; a long way from the 86.9MB but still better than 29.4MB/s (same buffer on battery). Keep in mind of the I/O required to keep the buffers full &#8211; it might be easier (and finally faster) to use smaller ones&#8230;</p>
<p>Running iOS application on AC power is uncommon for most people. However it&#8217;s <strong>not</strong> uncommon when developing and testing applications, including benchmarking them. <strong>Take care when testing yours!</strong> It took my a while and a bit of juggling between computers and devices to figure out why some numbers were so different than others.</p>
<p>Here is the new, <strong>battery operated</strong>, and the original (from the <a href="http://spouliot.wordpress.com/2012/04/30/managed-crypto-vs-commoncrypto/" title="Managed Crypto vs CommonCrypto">first blog post</a>), <strong>AC powered</strong>, performance graphics.</p>
<p><a href="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-28-at-11-14-36-am.png"><img src="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-28-at-11-14-36-am.png?w=640" alt="" title="Battery operated Cipher Performance"   class="aligncenter size-full wp-image-738" /></a></p>
<p><a href="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-12-at-3-17-20-pm.png"><img src="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-12-at-3-17-20-pm.png?w=640" alt="" title="Ciphers"   class="aligncenter size-full wp-image-621" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spouliot.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spouliot.wordpress.com/596/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=596&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spouliot.wordpress.com/2012/05/02/managed-crypto-vs-commoncrypto-deciphering-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dcbd727a1d3fe8eebba8b53e4d9ea4cf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spouliot</media:title>
		</media:content>

		<media:content url="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-27-at-8-18-45-pm.png" medium="image">
			<media:title type="html">ECB versus CBC</media:title>
		</media:content>

		<media:content url="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-27-at-8-47-03-pm.png" medium="image">
			<media:title type="html">Native vs Managed Performance</media:title>
		</media:content>

		<media:content url="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-28-at-11-14-36-am.png" medium="image">
			<media:title type="html">Battery operated Cipher Performance</media:title>
		</media:content>

		<media:content url="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-12-at-3-17-20-pm.png" medium="image">
			<media:title type="html">Ciphers</media:title>
		</media:content>
	</item>
		<item>
		<title>Managed Crypto vs CommonCrypto : Digesting results</title>
		<link>http://spouliot.wordpress.com/2012/05/01/managed-crypto-vs-commoncrypto-digesting-results/</link>
		<comments>http://spouliot.wordpress.com/2012/05/01/managed-crypto-vs-commoncrypto-digesting-results/#comments</comments>
		<pubDate>Tue, 01 May 2012 11:53:36 +0000</pubDate>
		<dc:creator>spouliot</dc:creator>
				<category><![CDATA[crypto]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[monotouch]]></category>
		<category><![CDATA[xamarin]]></category>

		<guid isPermaLink="false">http://spouliot.wordpress.com/?p=595</guid>
		<description><![CDATA[As part of MonoTouch&#8216;s switch to CommonCrypto most of the digest (hash) algorithm implementations were changed to use CommonDigest. This includes: MD5CryptoServiceProvider, SHA1[CryptoServiceProvider&#124;Managed], SHA256Managed, SHA384Managed and SHA512Managed inside mscorlib.dll; and MD2Managed, MD4Managed and SHA224Managed inside Mono.Security.dll If you know well &#8230; <a href="http://spouliot.wordpress.com/2012/05/01/managed-crypto-vs-commoncrypto-digesting-results/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=595&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>As part of <a href="http://ios.xamarin.com">MonoTouch</a>&#8216;s <a href="http://spouliot.wordpress.com/2012/04/30/managed-crypto-vs-commoncrypto/" title="Managed Crypto vs CommonCrypto">switch to CommonCrypto</a> most of the digest (hash) algorithm implementations were changed to use <a href="http://www.opensource.apple.com/source/CommonCrypto/CommonCrypto-7/CommonCrypto/CommonDigest.h" target="_blank">CommonDigest</a>. This includes:</p>
<ul>
<li><code><strong>MD5</strong>CryptoServiceProvider</code>, <code><strong>SHA1</strong>[CryptoServiceProvider|Managed]</code>, <code><strong>SHA256</strong>Managed</code>, <code><strong>SHA384</strong>Managed</code> and <code><strong>SHA512</strong>Managed</code> inside <code>mscorlib.dll</code>; and</li>
<li><code><strong>MD2</strong>Managed</code>, <code><strong>MD4</strong>Managed</code> and <code><strong>SHA224</strong>Managed</code> inside <code>Mono.Security.dll</code></li>
</ul>
<p>If you know well the <code><a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.aspx">System.Security.Cryptography</a></code> namespace then you&#8217;ll note this is every <a href="http://msdn.microsoft.com/en-us/library/System.Security.Cryptography.HashAlgorithm.aspx"><code>HashAlgorithm</code></a> except <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.ripemd160.aspx"><code><strong>RIPEMD160</strong>Managed</code></a> and all the extra ones Mono provides to support (mostly older) X.509 certificates.</p>
<p>This also has some indirect effects on some other types, e.g. all <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.hmac.aspx">HMAC</a> and MAC (e.g. <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.mactripledes.aspx">MACTripleDES</a>) implementations are using the <strong>default</strong> hash algorithm. This means that all of them, except for <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.hmacripemd160.aspx">HMACRIPEMD160</a>, are now using CommonCrypto and will be faster too.</p>
<p><strong>Note:</strong> <a href="http://www.mono-project.com">Mono</a> never followed the <code>[Managed|CryptoServiceProvider]</code> suffixes: by default everything <em>was</em> always managed and will <em>now</em> be native (for MonoTouch). So don&#8217;t be confused by the names. Source/binary compatibility requires Mono type names to match Microsoft, not how they are implemented.</p>
<p><strong>Performance</strong></p>
<p><a href="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-16-at-7-59-23-pm.png"><img src="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-16-at-7-59-23-pm.png?w=640" alt="" title="Digest Algorithms Performance"   class="aligncenter size-full wp-image-664" /></a></p>
<p>The best performance comes from <code>SHA1</code>, <strong>107 MB/second</strong> (mean values for my iPod4, iPad1 and iPad3 devices). This is also the best enhancement ratio, <strong>6.7x faster</strong> than managed &#8211; even if <code>SHA1</code> is the most optimized (i.e. unrolled) managed implementation Mono has. </p>
<p>The secret ? <strong>hardware acceleration</strong>. Apple&#8217;s <a href="http://opensource.apple.com/source/CommonCrypto/CommonCrypto-36064/Source/Digest/sha1.c">source code</a>, shows that hardware acceleration is being used (at least on some ARM devices) if the block being processed are large enough (to offset the cost of initializing the hardware).</p>
<p>It&#8217;s always a bit hard to be 100% certain we&#8217;re using the hardware as there&#8217;s no way to ask for (or against) it or even query it&#8217;s use / availability. In this case the numbers do not make it very clear, the curves are too similar between all native implementations to jump at a conclusion. My own gut feelings is that we&#8217;re seeing the effects of hardware acceleration but it lost its <em>shocking</em> effect because it&#8217;s compared to Mono&#8217;s best, performance-wise, implementation.</p>
<p><strong>Getting the most of the update</strong></p>
<p>The above graphic shows considerable performance gains: from 3.1x up to 6.7x. Now the question is: <strong>can we get such gains inside our applications ?</strong></p>
<p>Without surprise it comes back to <strong>selecting an optimal buffer size</strong> (and that advice is true for older MonoTouch, Mono itself and other Mono-based products). This is not always as easy as it sounds (e.g. SSL/TLS) but <em>if</em> you can control your buffer size (and measure) then you can get the best performance for your application.</p>
<p>The next graphics shows the performance (managed versus native) of SHA1. There&#8217;s no gain to use CommonCrypto before reaching 16 bytes but <em>surprisingly</em> there&#8217;s no loss either. That&#8217;s unlike the <a href="http://spouliot.wordpress.com/2012/02/27/cryptodev-support-in-crimson/" title="/dev/crypto support in Crimson">/dev/crypto</a> results and a <strong>very good news</strong> since it means this update should not degrade performance for existing applications.</p>
<p><a href="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-16-at-7-39-22-pm.png"><img src="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-16-at-7-39-22-pm.png?w=640" alt="" title="SHA1 performance"   class="aligncenter size-full wp-image-663" /></a></p>
<p>Another similarity: in both cases the optimal buffer size is (close to) 4096 bytes &#8211; and that&#8217;s also true for other algorithms as well. That should not be a huge surprise for managed code, since it&#8217;s the <a href="https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Security.Cryptography/HashAlgorithm.cs#L96">default value</a> Mono has used for years when computing the hash on a stream. </p>
<p>This is a (second) good news that the managed and native (and hardware) optimal buffer size are close enough so a single value can be shared. It simply makes coding easier for everyone <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>So that&#8217;s 6.7x increase is for real ?</strong> Not quite. Did not you hear me repeating benchmark are lies ?</p>
<p>Benchmarking cryptographic implementations can be (and generally is) done with minimal I/O. Memory (RAM) is much faster than disk (or any type of storage) and faster than networking. Beside the I/O times this also remove/reduce the need for memory allocations (and the related GC time).</p>
<p>OTOH your application, if it&#8217;s not a benchmark apps, will need to do a lot more I/O (loading, saving or transmitting the data) that will result in memory allocations&#8230; all of which will reduce the performance gain. Also the faster the cryptographic implementation becomes the less forgiving it will be for I/O times.</p>
<p>So your mileage <strong>will</strong> vary. Someone already <a href="https://twitter.com/#!/andytwittt/status/197004108236984321">reported</a> gains near <strong>3-4x</strong>, which is quite impressive inside a real application. IMO the best news is the lack of scenarios where things gets worse &#8211; it should be a win for everyone <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spouliot.wordpress.com/595/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spouliot.wordpress.com/595/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=595&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spouliot.wordpress.com/2012/05/01/managed-crypto-vs-commoncrypto-digesting-results/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dcbd727a1d3fe8eebba8b53e4d9ea4cf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spouliot</media:title>
		</media:content>

		<media:content url="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-16-at-7-59-23-pm.png" medium="image">
			<media:title type="html">Digest Algorithms Performance</media:title>
		</media:content>

		<media:content url="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-16-at-7-39-22-pm.png" medium="image">
			<media:title type="html">SHA1 performance</media:title>
		</media:content>
	</item>
		<item>
		<title>Managed Crypto vs CommonCrypto</title>
		<link>http://spouliot.wordpress.com/2012/04/30/managed-crypto-vs-commoncrypto/</link>
		<comments>http://spouliot.wordpress.com/2012/04/30/managed-crypto-vs-commoncrypto/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 12:16:55 +0000</pubDate>
		<dc:creator>spouliot</dc:creator>
				<category><![CDATA[crimson]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[monotouch]]></category>
		<category><![CDATA[xamarin]]></category>

		<guid isPermaLink="false">http://spouliot.wordpress.com/?p=23</guid>
		<description><![CDATA[A bit of history… Mono has always provided fully managed implementations of almost every cryptographic algorithms supported by .NET, either directly (in the base class libraries) or indirectly (e.g. additional algorithms required for X.509 or SSL/TLS support). That approach gets &#8230; <a href="http://spouliot.wordpress.com/2012/04/30/managed-crypto-vs-commoncrypto/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=23&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><strong>A bit of history…</strong></p>
<p><a href="http://www.mono-project.com" title="Mono">Mono</a> has always provided fully managed implementations of <em>almost</em> every cryptographic algorithms supported by .NET, either directly (in the base class libraries) or indirectly (e.g. additional algorithms required for X.509 or SSL/TLS support).</p>
<p>That approach gets you full cryptographic support <strong>everywhere</strong> the Mono JIT/runtime itself works, which covers a pretty large spectrum, with no external dependency required.</p>
<p>Now this was not always the best choice for performance but it did not matter much since .NET (and Mono) crypto stack is meant to be extendable and replaceable thru <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.cryptoconfig.aspx">CryptoConfig</a>. E.g. you can find some faster alternatives inside <a href="https://github.com/mono/crimson">Crimson</a> using <a href="https://github.com/mono/crimson/tree/master/class/Crimson.MHash">libmhash</a> or <code><a href="http://spouliot.wordpress.com/2012/02/27/cryptodev-support-in-crimson/" title="/dev/crypto support in Crimson">/dev/crypto</a></code>.</p>
<p><strong>Back to MonoTouch…</strong></p>
<p>Things in iOS-land are a bit different. Extensibility does not work as well because of the platform restrictions MonoTouch must abide to. The mono runtime and the class libraries are not shared (each application get its own) often tailored (by both linkers) copies. Not to mention you cannot share code between applications or even load code dynamically. That effectively kills all the benefits that <code>CryptoConfig</code> can provide.</p>
<p>OTOH the lack of control, as a owner, over the device&#8217;s operating system means we, as developers, know what&#8217;s in there. In this case we can be sure that CommonCrypto is always present. It&#8217;s an external dependency but not an optional or additional dependency.</p>
<p>Since we can&#8217;t offer extensibility we need to choose what&#8217;s offered. In MonoTouch 5.2 (and earlier) that was the managed implementations. For the <em>upcoming</em> MonoTouch 5.4 (starting now with 5.3.3 alpha) this will be CommonCrypto-based implementations. </p>
<p><strong>Why ?</strong> Switching has three benefits:</p>
<p><strong>1. <em>Likely</em> incoming FIPS 140 certification</strong></p>
<p>Thanks to NIST it&#8217;s no <a href="http://csrc.nist.gov/groups/STM/cmvp/documents/140-1/140InProcess.pdf">secret</a> (pdf) that Apple is been seeking FIPS 140 certifications for CommonCrypto on iOS. This can be a long process but intermediate results, like <a href="http://csrc.nist.gov/groups/STM/cavp/documents/aes/aesval.html#1673">AES validations</a>, can already be found online.</p>
<p>It does not mean much today (in progress == no certification) but it could become crucial for some applications, if you want to sell them to either the US or Canadian federal government, in the future. Whenever it happens you&#8217;ll be ready, not waiting, for this <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>2. Smaller application size</strong></p>
<p>Inside .NET assemblies p/invoke declarations are methods without any body (no IL, just metadata). As such they tend to be small &#8211; much smaller than the cryptographic code they replace (even with the additional glue code needed).</p>
<p>This means that by using <code>CommonCrypto</code> we can reduce the size of <code>mscorlib.dll</code> (-19.5 KB), <code>System.Core.dll</code> (-12 KB) and <code>Mono.Security.dll</code> (-2 KB). Also the internal calls required for the pseudo random number generator (PRNG) can be <a href="http://spouliot.wordpress.com/2012/03/21/managed-vs-native-linkers/" title="Managed vs Native Linkers">eliminated by the native linker</a>.</p>
<p>As a result my benchmarking application, fully linked and compiled using LLVM for ARMv7 (Release), <strong>is 99.5KB smaller</strong> than before. That does not include the effects of the other features added in <a href="http://docs.xamarin.com/ios/releases/MonoTouch_5/MonoTouch_5.3">MonoTouch 5.3</a> &#8211; with all the other enhancements the size, when compared to 5.2.11, is <strong>219 kb smaller</strong>.</p>
<p><strong>3. Better performance</strong></p>
<p>Even if it&#8217;s not hard to find counterexamples native code generally outperforms managed code. That&#8217;s often the case for cryptographic code that is optimized or, in some cases, hardware accelerated (recent iOS devices offer this for SHA1 and AES in CBC mode).</p>
<p>For MonoTouch (or Mono in general) this is true when the buffer size are large enough that the managed/native transition cost can be hidden by the faster code. With an <strong>optimal</strong> buffer size I get the following results when comparing benchmarks on the existing managed code (5.2.11) versus the new CommonCrypto-based code (5.3.3).</p>
<p><a href="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-12-at-3-16-51-pm.png"><img src="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-12-at-3-16-51-pm.png?w=640" alt="" title="Digests"   class="aligncenter size-full wp-image-620" /></a></p>
<p><a href="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-12-at-3-17-20-pm.png"><img src="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-12-at-3-17-20-pm.png?w=640" alt="" title="Ciphers"   class="aligncenter size-full wp-image-621" /></a></p>
<p>The vertical scale represents the improvement factor, i.e. Managed is 1x. Now <strong>forget</strong> about the high end (AES) numbers that changes the scale of the graphic. I&#8217;ll share the exact incantations and sacrifices required, in a future post, but you&#8217;re <strong>not</strong> likely to get them (or even half of them) in real life conditions. Part of it is because <a href="http://spouliot.wordpress.com/2012/02/27/cryptodev-support-in-crimson/" title="/dev/crypto support in Crimson">benchmarks are lies</a> and a <em>funny</em> fact makes this one an even bigger liar than usual.</p>
<p>Still those are impressive gains that requires nothing but recompiling your application with MonoTouch 5.3.3 (or later). Technical details about what changed and more graphics to follow&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spouliot.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spouliot.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=23&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spouliot.wordpress.com/2012/04/30/managed-crypto-vs-commoncrypto/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dcbd727a1d3fe8eebba8b53e4d9ea4cf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spouliot</media:title>
		</media:content>

		<media:content url="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-12-at-3-16-51-pm.png" medium="image">
			<media:title type="html">Digests</media:title>
		</media:content>

		<media:content url="https://spouliot.files.wordpress.com/2012/04/screen-shot-2012-04-12-at-3-17-20-pm.png" medium="image">
			<media:title type="html">Ciphers</media:title>
		</media:content>
	</item>
		<item>
		<title>Linker versus Customization</title>
		<link>http://spouliot.wordpress.com/2012/04/27/linker-versus-customization/</link>
		<comments>http://spouliot.wordpress.com/2012/04/27/linker-versus-customization/#comments</comments>
		<pubDate>Fri, 27 Apr 2012 20:36:03 +0000</pubDate>
		<dc:creator>spouliot</dc:creator>
				<category><![CDATA[linker]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[monotouch]]></category>
		<category><![CDATA[xamarin]]></category>

		<guid isPermaLink="false">http://spouliot.wordpress.com/?p=678</guid>
		<description><![CDATA[MonoTouch 5.3.3 (alpha) has been released with lots of new goodies (and I can predict a few blog posts about them). Let&#8217;s start slowly since it&#8217;s already the end of the week&#8230; There&#8217;s a lot of ways to customize how &#8230; <a href="http://spouliot.wordpress.com/2012/04/27/linker-versus-customization/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=678&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://docs.xamarin.com/ios/releases/MonoTouch_5/MonoTouch_5.3#MonoTouch_5.3.3">MonoTouch 5.3.3</a> (alpha) has been released with <strong>lots</strong> of new goodies (and I can predict a few blog posts about them). Let&#8217;s start slowly since it&#8217;s already the end of the week&#8230;</p>
<p>There&#8217;s a lot of ways to customize how the <a href="http://docs.xamarin.com/ios/advanced_topics/linker">linker</a> works on your applications. They covers the most common scenarios but it can sometime feels like it&#8217;s missing a final <code>else { }</code> condition. Let&#8217;s review the existing conditions:</p>
<p>First the linker&#8217;s scope. You can use it on everything (<code>--linkall</code>), on the SDK assemblies shipped with MonoTouch (<strong>default</strong>) or not at all (<code>--nolink</code>). You can further suppress the linker from executing on one or several assemblies using <code>--linkskip=MyAssembly</code>.</p>
<p>You can also control how the linker code works on your own assemblies. Using the <code><a href="http://iosapi.xamarin.com/?link=T%3aMonoTouch.Foundation.PreserveAttribute">[Preserve]</a></code> attribute you can ensure that specific parts of your code won&#8217;t be linked away (e.g. for reflection/serialization usage). With few (or even no) adjustments most applications can use <code>--linkall</code> and reduce their final size.</p>
<p>Controlling the code linked inside SDK assemblies is less common and a bit harder. The most common way is to write code that use the type, method or fields that you <strong>do not</strong> want removed. That works well unless you need to preserve some private/internal code. In such case you&#8217;re a bit out of luck as using reflection won&#8217;t be seen by the linker. Using <code>--linkskip</code> is often your best solution &#8211; but you lose the linker benefits over the entire assembly.</p>
<p>Sad ? <strong>No more</strong>. Starting with 5.3.3 you&#8217;ll be able to add extraneous declarations using the new <code>--xml</code> option. Writing XML is never a first choice (at least for me) but it will allow you complete control <strong>on your own code</strong> (e.g. you do not want or cannot use <code>[Preserve]</code>) and <strong>on the SDK assemblies</strong> shipped with MonoTouch.</p>
<p>Not surprised ? You should not be <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  as this is not something <em>really</em> new. The original <code><a href="https://github.com/mono/mono/tree/master/mcs/tools/linker">monolinker</a></code> has always supported this. It is even used, internally, by <code>mtouch</code>, for the XML definitions used for SDK assemblies (you can find a few similar examples <a href="https://github.com/mono/mono/tree/master/mcs/tools/linker/Descriptors">here</a>). However this option was not exposed to MonoTouch developers before 5.3.3.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spouliot.wordpress.com/678/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spouliot.wordpress.com/678/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=678&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spouliot.wordpress.com/2012/04/27/linker-versus-customization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dcbd727a1d3fe8eebba8b53e4d9ea4cf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spouliot</media:title>
		</media:content>
	</item>
		<item>
		<title>Touch.Unit Automation Revisited</title>
		<link>http://spouliot.wordpress.com/2012/04/02/touch-unit-automation-revisited/</link>
		<comments>http://spouliot.wordpress.com/2012/04/02/touch-unit-automation-revisited/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 11:46:04 +0000</pubDate>
		<dc:creator>spouliot</dc:creator>
				<category><![CDATA[mono]]></category>
		<category><![CDATA[monotouch]]></category>
		<category><![CDATA[touch.unit]]></category>
		<category><![CDATA[xamarin]]></category>

		<guid isPermaLink="false">http://spouliot.wordpress.com/?p=311</guid>
		<description><![CDATA[The basics for test automation have been in place for a while. However that was more potential for automation that real automation. Too many things, outside the Touch.Unit application, were still missing. Since that time Rolf has filled those missing &#8230; <a href="http://spouliot.wordpress.com/2012/04/02/touch-unit-automation-revisited/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=311&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The <a href="http://spouliot.wordpress.com/2011/10/13/touch-unit-automation/" title="Touch.Unit Automation">basics</a> for test automation have been in place for a while. However that was more <em>potential</em> for automation that <em>real</em> automation. Too many things, outside the <a href="http://spouliot.wordpress.com/2011/09/28/unit-testing-and-monotouch/" title="Unit testing and MonoTouch ?">Touch.Unit</a> application, were still missing.</p>
<p>Since that time <a href="http://rolfkvinge.blogspot.com/">Rolf</a> has filled those missing pieces, mainly in the <a href="https://github.com/spouliot/Touch.Unit/tree/master/Touch.Server">Touch.Server</a> tool, to allow <a href="http://spouliot.wordpress.com/2011/09/28/unit-testing-and-monotouch/" title="Unit testing and MonoTouch ?">Touch.Unit</a> projects to be build, executed on the simulator and/or on devices, and to receive all the test results on a local file for further processing and reporting.</p>
<p><strong>So how do I do that ?</strong> All the tools are already available, i.e. it&#8217;s all in the stable <a href="http://xamarin.com/monotouch">MonoTouch</a> 5.2.x releases. All it takes is some minimal scripting to adapt it to your application.</p>
<p>Here&#8217;s an example (<a href="https://github.com/spouliot/Touch.Unit/blob/master/Makefile">Makefile</a>) of how this can be done for Touch.Unit itself (i.e. the sample tests it includes).</p>
<pre class="brush: bash; title: ; notranslate">
MDTOOL=/Applications/MonoDevelop.app/Contents/MacOS/mdtool
MTOUCH=/Developer/MonoTouch/usr/bin/mtouch
TOUCH_SERVER=./Touch.Server/bin/Debug/Touch.Server.exe

all: build-simulator build-device

run run-test: run-simulator run-device

$(TOUCH_SERVER):
	cd Touch.Server &amp;amp;&amp;amp; xbuild

build-simulator:
	$(MDTOOL) -v build -t:Build &quot;-c:Debug|iPhoneSimulator&quot; Touch.Unit.sln

run-simulator: build-simulator Touch.Server
	rm -f sim-results.log
	mono --debug $(TOUCH_SERVER) --launchsim bin/iPhoneSimulator/Debug/TouchUnit.app -autoexit -logfile=sim-results.log
	cat sim-results.log

build-device:
	$(MDTOOL) -v build -t:Build &quot;-c:Release|iPhone&quot; Touch.Unit.sln

run-device: build-device
	$(MTOUCH) --installdev bin/iPhone/Release/TouchUnit.app
	# kill an existing instance (based on the bundle id)
	$(MTOUCH) --killdev com.xamarin.touch-unit
	rm -f dev-results.log
	mono --debug $(TOUCH_SERVER) --launchdev com.xamarin.touch-unit -autoexit -logfile=dev-results.log
	cat dev-results.log
</pre>
<p>This small <code>Makefile</code> shows you how to use:</p>
<ul>
<li><code>mdtool</code> to build an existing MonoDevelop solution, Debug or Release;</li>
<li><code>mtouch</code> to install and kill (running) applications on devices; and</li>
<li><code>Touch.Server</code> to start application, including specifying arguments.</li>
</ul>
<p>All of them can be useful in other circumstances but for our purpose you can simply issue a <code>make run-test</code> from a terminal window to execute the test cases on both the simulator and a connected device.</p>
<p>p.s. you should all encourage Rolf to blog more often has he&#8217;s doing incredible stuff all around <a href="http://ios.xamarin.com" title="MonoTouch" target="_blank">MonoTouch</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/spouliot.wordpress.com/311/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/spouliot.wordpress.com/311/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=spouliot.wordpress.com&#038;blog=25386334&#038;post=311&#038;subd=spouliot&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://spouliot.wordpress.com/2012/04/02/touch-unit-automation-revisited/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dcbd727a1d3fe8eebba8b53e4d9ea4cf?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">spouliot</media:title>
		</media:content>
	</item>
	</channel>
</rss>
