Home

Awesome

Xamarin.Forms.Benchmarks

Example of using BenchmarkDotNet to write some benchmarks for Xamarin.Forms concepts.

Results of different bindings

Running on Windows .NET framework:

MethodMeanErrorStdDevGen 0Gen 1Gen 2Allocated
ByHandOneTime3.210 us0.0836 us0.0553 us0.55310.0038-3.42 KB
TypedOneTime4.087 us0.0560 us0.0370 us0.81630.0076-5.05 KB
RegularOneTime5.375 us0.0117 us0.0077 us0.90790.0076-5.61 KB
ByHand5.552 us0.6508 us0.4305 us0.59510.1450-3.71 KB
Typed6.992 us0.4679 us0.3095 us0.91550.3052-5.67 KB
Regular7.822 us0.3988 us0.2638 us0.94600.3128-5.86 KB

Using BenchmarkDotnet for Xamarin.Forms in a Console app

This is likely the simplest option. Setup BenchmarkDotNet as you would for a normal .NET console app.

This is what I normally do:

static void Main(string[] args)
{
    var config = default (IConfig);
#if DEBUG
    // If you want to debug your benchmarks, you need this
    // When taking final measurements, use a Release build.
    config = new DebugInProcessConfig ();
#endif
    BenchmarkSwitcher.FromAssembly (typeof (Program).Assembly).Run (args, config);
}

If you want to use Xamarin.Forms on desktop, use my Xamarin.Forms.Mocks mocking library. This will allow you to benchmark Xamarin.Forms.Core and Xamarin.Forms.Xaml independent of any platform-specific code.

Using BenchmarkDotNet in your Xamarin.Android/iOS project

If trying to get this working in a mobile application project, a couple of notes:

Otherwise, the bulk of the work is going to be making a simple UI for choosing benchmarks and running them.

Check out BenchmarkDotNet's samples for details.