Does anyone have benchmarks (code & results) comparing performance of Android apps written in Xamarin C# and Java? [closed]

◇◆丶佛笑我妖孽 提交于 2019-11-26 21:12:44

Yeah, Xamarin's Mono virtual machine is more impressive than Google's Dalvik used in Android. I have tested it with HTC Flyer and Acer Iconia Tab tablets to benchmark the C# port of Android through Mono against Java Dalvik, with the C# implementation of Android well and truly trouncing the Java-based Dalvik.

I came across this interesting post

https://medium.com/@harrycheung/mobile-app-performance-redux-e512be94f976#.kfbauchtz

Hope this information helps.

We recently investigated using Xamarin for an app. We utilized the C# code we had already written for the Windows RT version of our app. Some specific details had to be rewritten for the Android version.

What we discovered is that I/O in Xamarin C# is approximately 2x slower than Java. Our app is heavily I/O bound. We have not discovered the cause of this yet, but at the moment we are assuming that it is due to marshaling. While we do try to stay inside the Mono VM most of the time, we do not know how Mono actually accesses the disk.

It is also telling that our C# code uses SQLite.NET (https://github.com/praeclarum/sqlite-net). Identical fetches using the SQLite.NET code are also 2x slower than using Android's Java SQLite wrapper. After looking at the source code, it appears to bind directly to the C .dll, so I do not know why it's so much slower. One possibility is that marshaling strings from native to Java may be faster on Android than native to C# is on Xamarin.

Daniel

This is another more updated blog post I would like to share with you. He compares Xamarin to native code and Cordova on both IOs and Android.

In a nutshell, Xamarin performs sometimes better than native code. He tested the app size, load times, loading a list from Azure service and prime number computation.

Enjoy!

Edit: I updated the dead link and I noticed that there is a part 2

Burgito

Here are a few informations I found in another test between native, Xamarin and Xamarin.Forms solutions (the tests also include iOS performances) on the two following devices :

Samsung Galaxy A7: Android OS version: 6.0 Central-processing unit: Octa-core 1.9 GHz Cortex-A53 RAM: 3GB Display resolution: 1920×1080

iPhone 6s: iOS version: 10.3.3 Central-processing unit: Dual-core 1.84 GHz Twister RAM: 2 GB Display resolution: 1334×750

Comparison is made on a few common features, each one with its own application :

- Basic “Hello World”
- REST API
- JSON Serialization/Deserialization
- Photo Loading
- SQL Database Insert and Get All

Each test is repeted several times, the graphs show the average results.


Hello World


Rest API

Set of tests aimed at measuring the time it takes for the app to send a request through REST API and receive the response back without further data processing, using OpenWeatherMap API.


JSON Operations Tests made using Newtonsoft Json.net framework to serialize and deserialize JSON objects in all Xamarin apps. Native Android serialization and deserialization tested using two Java libraries: Jackson and GSON.

Two runs are made, one first from scratch and a second one with cached infos and operations

First run :

(Native iOS JSON Operations is killing this test btw, and Xamarin joins it in the second)


Photo Operations

First load on images with three different resolutions :

Resolution – 858×569, Size – 868Kb
Resolution – 2575×1709, Size – 8Mb
Resolution – 4291×2848, Size – 28.9Mb

Something seemed unsure about the Xamarin.Forms results for this test, so it is not included in the graph.


SQLite Operations

Two operations tested :

BulkInsert: Loading rows of data into a database table.
GetAll: Retrieving all data from the database.

With databases having 10,000 records. All operations were processed internally on devices.


Xamarin Native (Xamarin.iOS/Xamarin.Android) show themselves as rather good alternatives to the native code, whereas Xamarin.Forms seems slow in a lot of cases, but it can be a really good solution to develop really simple applications fastly.

Complete test comes from this source :

https://www.altexsoft.com/blog/engineering/performance-comparison-xamarin-forms-xamarin-ios-xamarin-android-vs-android-and-ios-native-applications/

Thank you for giving me the explanations to enhance my answer, hope this helps a little :)

Rolf ツ

Performance

Performance is a vague word if you don't define what you mean by performance, if it's plain computation performance Xamarin can be faster than Java depending on the nature of the computation.

Android nativly comes with multipe forms to execute code in:

  • RenderScript (CPU and GPU)
  • Java (SDK)
  • C++ (NDK)
  • OpenGL (GPU)

It is quite obvious that when executing code the more native the solution the faster it will be. A run-time based language will never beat a language that directly runs on the CPU.

But on the other hand if you want to measure real-life usage performance Java is propbaby going to be faster then Xamarin.

Xamarin and why it can be slower

When comparing Xamarin with plain old Java applications, performance can very well be faster for Xamarin as it can be slower.

In a real world example Xamarin applications are very likely to be slower than Java applications because many Android/Java (system) calls need to be delegated to and from the Xamarin run-time using so called bindings.

There are a few different types of bindings that are important to know:

  • JNI (Java Native Interface): The binding used in many android applications to interface between Java code (SDK) and native C++ code (NDK).
  • MCW (Managed Callable Wrappers): A binding that is available in Xamarin to interface from managed C# code to Java code (Android run-time).
  • ACW (Android Callable Wrappers): A binding that is available in Xamarin to interface from Java code (Android run-time) to managed C# code.

More on MCW and ACW here: https://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/part_1_-_understanding_the_xamarin_mobile_platform/

Bindings are in terms of performance very very costly. Invoking a C++ method from Java adds a huge overhead in calling time, calling a C++ method from within C++ is many many many times faster.

Someone did a performance test to calculate how many Java operations on average a JNI call costs: What is the quantitative overhead of making a JNI call?

But not only JNI calls are costly so are calls to and from MCW and ACW. Real world Xamarin applications make many calls using bindings and because of this real world usage of an Xamarin application can be (and will be in general) slower than a plain old Java application. However depending on how the Xamarin application was designed it is very likely that the user won't even notice the difference.

TLDR/Conclusion: Xamarin needs to using al sorts bindings, which are time costly.

Besides bindings, there are many other factors involved when talking about real-world performance, for example: size of the binary, loading the app in memory, I/O operations and many more. A blog post that investigates some of these things can be found here: https://magenic.com/thinking/mobile-development-platform-performance-part-2-native-cordova-classic-xamarin-xamarin-forms

Denis Gordin

It's pretty old tests but could be relevant: https://github.com/EgorBo/Xamarin.Android-vs-Java

Arithmetic test

Collections, generics, custom value types

Working with strings

UPD: new data with Google Pixel 2 (thanks yousha-aleayoub)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!