Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic BenchmarkDotNet support for Xamarin #1360

Merged
merged 1 commit into from
Apr 9, 2020

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Jan 27, 2020

Fixes: #1343

This is basically an "MVP" of Xamarin support with BenchmarkDotNet.

At a high level:

  1. Simple benchmarks work with default config settings.

  2. You can write a Xamarin.Forms app that runs benchmarks and displays
    the results. I added a very basic sample of this.

Some of the details to get this working:

  • ConsoleExitHandler.CancelKeypress throws
    PlatformNotSupportedException on Xamarin platforms. Just ignore
    this exception.

  • Multi-target BenchmarkDotNet.Samples to include netstandard2.0.
    This allows me to reference the benchmarks from the Xamarin.Forms
    shared code. I had to exclude some Windows-specific benchmarks.

  • Don't probe for mono binary for InProcess. This was breaking
    InProcess for Xamarin, in general. It's not going to find a mono
    binary that doesn't exist.

  • Detect Xamarin.Android / Xamarin.iOS. I used the most common
    Type.GetType lookup to detect each platform: Java.Lang.Object
    and Foundation.NSObject.

  • Fix for Directory.CurrentDirectory() as ArtifactPath. The
    current directory on Android is not writeable. Looking for /,
    seemed like a simple fix for Android.

  • Default to InProcess for Xamarin platforms. Since we can't find a
    mono binary, we have to run in-process. Xamarin.iOS also shouldn't
    use System.Reflection.Emit until the interpreter is more stable.
    Users of BDN can experiment with the interpreter by configuring
    their benchmarks manually.

This is the first I've looked at this repo, so suggestions welcome! I don't
know this codebase.

The bulk of the new files here is what you get from a new Xamarin.Forms
template in Visual Studio. We can trim that down if needed. Thanks!

Screen Shot 2020-01-27 at 8 47 32 AM

@jonathanpeppers
Copy link
Member Author

Questions:

  1. The Xamarin projects won't be able to build with dotnet build until we ship .NET 5. Should I just remove them from the main SLN file for now?
  2. Is there a doc I should update to mention how to use with Xamarin?

@jonathanpeppers
Copy link
Member Author

jonathanpeppers commented Jan 31, 2020

  1. The Xamarin projects won't be able to build with dotnet build until we ship .NET 5. Should I just remove them from the main SLN file for now?
  2. Is there a doc I should update to mention how to use with Xamarin?

@adamsitnik or @AndreyAkinshin any thoughts about this? thanks!

@adambarath
Copy link

Hi! Any updates on this? BR

@jonathanpeppers
Copy link
Member Author

@adambarath I never heard anything back on this.

I'll use my best judgement to make this "mergeable" and maybe we'll hear back by then?

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the changes introduced to the main part of BenchmarkDotNet look very good to me 👍

It's great that you have added samples, but I would prefer to keep them in a separate solution. It could be called BenchmarkDotNet.Xamarin. My main motivation is to make sure that other contributors don't need to install any new prerequisites to be able to build main solution. We also don't need to introduce any big changes to our CI.

@AndreyAkinshin do you agree on having a standalone solution for the Xamarin purposes?

adamsitnik
adamsitnik previously approved these changes Apr 8, 2020
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Big thanks for adding the docs!

* Multi-target `BenchmarkDotNet.Samples` to include `netstandard2.0`
* Don't probe for `mono` binary for `InProcess`
* Detect Xamarin.Android / Xamarin.iOS
* Fix for `Directory.CurrentDirectory()` as `ArtifactPath`
* Default to `InProcess` for Xamarin platforms
* Added documentation, sample, and a new `BenchmarkDotNet.Xamarin.sln`
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@wcoder
Copy link

wcoder commented Aug 4, 2020

It looks like the documentation hasn't been deployed yet
https://benchmarkdotnet.org/articles/samples/IntroXamarin.html ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Question: possible to use with Xamarin?
4 participants