-
-
Notifications
You must be signed in to change notification settings - Fork 975
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
How to get benchmarks running from LINQPad? #580
Comments
It's not a bug, it's a feature. We have decided that BenchmarkDotNet shouldn't allow running benchmarks in DEBUG. Why do you want to run your benchmark without optimizations? |
So I have set the "compile with /optimize+" setting in linqpad, which from my understanding is the equivalent of release mode, and it still doesn't run
Or am I misunderstanding and the issue is that linqpad itself is not optimized? |
Hello @michael-wolfenden Thanks for reporting your issue. I have just pushed a commit with the fix (we detect that user is using LINQPad and has optimizations disabled and give nice error message). However as you have noticed LINQPad itself is non-optimized. To overcome this problem please use custom config with our policy disabled: public class AllowNonOptimized : ManualConfig
{
public AllowNonOptimized()
{
Add(JitOptimizationsValidator.DontFailOnError); // ALLOW NON-OPTIMIZED DLLS
Add(DefaultConfig.Instance.GetLoggers().ToArray()); // manual config has no loggers by default
Add(DefaultConfig.Instance.GetExporters().ToArray()); // manual config has no exporters by default
Add(DefaultConfig.Instance.GetColumnProviders().ToArray()); // manual config has no columns by default
}
}
BenchmarkRunner<YourType>(new AllowNonOptimized()); |
@albahari is there any reason why LINQPad is non-optimized? It would make our user experience much better if it was optimized. You can use following settings in your csproj to have nice symbol information in pdb and optimizations enabled for Release: <DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols> |
Because the performance-critical libraries that LINQPad uses are optimized (libraries such as Roslyn & ActiPro's syntax editor), there's not much to gain in optimizing LINQPad itself. And there's a lot to lose - namely, the quality of the diagnostic information when an error occurs. Just recently, I've diagnosed an intermittent hang based on a stack trace which might have been compromised with optimizations enabled. I think users would rather have better reliability and quicker bug fixes than the small perf gain that optimizations would yield in this situation. In the case of BenchmarkDotNet, the message about LINQPad not being optimized is a false alarm, because LINQPad's non-optimized code should not find its way into the code paths being tested (unless you're performance-testing features of LINQPad itself - such as LINQPad's Dump or Dif methods). LINQPad is like the IDE, so it shouldn't really be counted in this scenario. Could I can add an assembly attribute to LINQPad to signal this? Obviously I can't take a dependency on BenchmarkDotNet, but I could define an attribute class like the following in LINQPad, and you could detect it by looking at the full type name:
|
@albahari thanks for the explanation! I have added LINQPad to our "white list", so everything should work fine now. |
@adamsitnik Will this require a new release of BenchmarkDotNet or has it already made it into a release? I've just moved to a new device and had to employ the custom config workaround (which in my case is not a big deal; this is more of a notification type question). |
@ZodmanPerth hi! It will be a part of 0.10.11. @AndreyAkinshin could you trigger our CI build? It has failed for some magical reason @ZodmanPerth as soon as our CI builds the package, it should be available at <packageSources>
<add key="bdn-nightly" value="https://ci.appveyor.com/nuget/benchmarkdotnet" />
</packageSources> |
@adamsitnik, done. |
Thanks. |
Hi @ZodmanPerth Our CI had some issues. Now we publish NuGet package again ;) You can try <packageSources>
<add key="bdn-nightly" value="https://ci.appveyor.com/nuget/benchmarkdotnet" />
</packageSources> |
Thanks @adamsitnik . By the time I was able to take action on this the nightly build was up to |
@ZodmanPerth thanks for the confirmation! |
Please include usings/opens in examples. |
JitOptimizationsValidator is in BenchmarkDotNet.Validators; however it's not necessary for LINQPad. No special configuration is required to run BenchmarkDotNet in LINQPad other than to ensure that your query itself is optimized, which you can do either via the LINQPad UI or with the following directive:
(If you forget, you'll get a message telling you specifically to add this directive.) Also note that recent LINQPad betas (7.5.x) have direct support for BenchmarkDotNet. You no longer need to reference BenchmarkDotNet, nor add any directives or benchmarking attributes, nor call the Benchmark runner (although these things are still supported). Instead, just highlight the statements you wish to benchmark (or a group of methods) and press Ctrl+Shift+B. A realtime visualization appears as benchmarking takes place: More info is in LINQPad's built-in samples. Press Ctrl+F1 to search the samples and type 'benchmark'. LINQPad 7.5 will go RTM within the next few weeks. |
Running the following code in LINQPad5 v5.25.00 referencing BenchmarkDotNet 0.10.10.339
Outputs the following and does not run
This appears to be a regression as the same script referencing BenchmarkDotNet 0.10.8.246 outputs
The text was updated successfully, but these errors were encountered: