BenchmarkDotNet in LinqPad
Hi all,
I'm just not able to move forward with BenchmarkDotNet in LinqPad.
Basically I have same problem as tym32167 on his github issue :
https://github.com/dotnet/BenchmarkDotNet/issues/593#issue-276705515
https://github.com/dotnet/BenchmarkDotNet/issues/580
Adam Sitnik is saying that the issue was solved, but it doesn't work.
BenchmarkDotNet version 0.11.5.1095 (their CI nuget server)
LinqPad version 5.39.00
Roslyn Preview > Use experimental Roslyn assemblies. (but checking or unchecking this doesn't make any difference)
Compiler optimization on (/o+)
Do not shadow assembly reference True.
I kindly ask you to any how-to, if there's any.
Thanks.
I'm just not able to move forward with BenchmarkDotNet in LinqPad.
Basically I have same problem as tym32167 on his github issue :
https://github.com/dotnet/BenchmarkDotNet/issues/593#issue-276705515
// Validating benchmarks: Assembly LINQPadQuery, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null is located in temp. If you are running benchmarks from xUnit you need to disable shadow copy. It's not supported by design.I'm trying to run a sample from benchmarkdotnet issue 580
https://github.com/dotnet/BenchmarkDotNet/issues/580
void Main() { var summary = BenchmarkRunner.Run<Md5VsSha256>(); } public class Md5VsSha256 { private const int N = 10000; private readonly byte[] data; private readonly SHA256 sha256 = SHA256.Create(); private readonly MD5 md5 = MD5.Create(); public Md5VsSha256() { data = new byte[N]; new Random(42).NextBytes(data); } [Benchmark] public byte[] Sha256() => sha256.ComputeHash(data); [Benchmark] public byte[] Md5() => md5.ComputeHash(data); }
Adam Sitnik is saying that the issue was solved, but it doesn't work.
BenchmarkDotNet version 0.11.5.1095 (their CI nuget server)
LinqPad version 5.39.00
Roslyn Preview > Use experimental Roslyn assemblies. (but checking or unchecking this doesn't make any difference)
Compiler optimization on (/o+)
Do not shadow assembly reference True.
I kindly ask you to any how-to, if there's any.
Thanks.
Comments
It's quite possible that LINQPad 6 will end up with a built-in benchmarking utility of some sort. If it did, what kind of features would you need?
First of all, I have to appologize, actually I'm able to run the sample benchmark.
Yesterday I had to mix up some code and it look like not running.
Today I made a sample from scratch.
The line
Assembly LINQPadQuery, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null is located in temp.
is still in the output, but actually the benchmark is running.I'm bit confused by your answer, Benchmark.net is available also for full .net framework.
https://benchmarkdotnet.org/articles/overview.html
I was able to run sample benchmark (from the example above) in .net core 2.1.11 and full .Net Framework 4.7.2.
It also doesn't expect csproj file. You can create console application and run it.
To answer your question regarding benchmarking features. I can use benchmarkdotnet in LinqPad (well, mostly, see below) and I don't necessarily need special LinqPad benchmarking features.
They also made special logger for LinqPad. (PR 903 and PR 915)
https://github.com/dotnet/BenchmarkDotNet/pulls?q=is:pr+linqpad+is:closed
That left me with thinking, that there is maybe problem somewhere else.
And indeed my problem is with the generated TypedDataContext.
Actually I'd like to benchmark FileStream feature of SQL Server.
I made a table and the Benchmark test the problem is that
Records
are not recognized as I would like to.With an error
CS0120 An object reference is required for the non-static field, method, or property 'TypedDataContext.Records'
This is actually not a problem of Benchmark Dotnet. This problem is shown in any class which tries to access data.
See example. Method GetFirst of a class AccessFromAclass doesn't work. Is there any way how to fix that ?
Thanks !
(also probably this thread should be renamed to something like Accessing TypedDataContext from a class)
There are (at least) two ways to work around this. (I can't you which is best in your case, because I've not had any luck in getting Benchmarkdotnet to work at all.)
The first is to keep it all in the same class: The other is to use the static variable Util.CurrentDataContext:
thanks for the info.
Especially
(UserQuery)Util.CurrentDataContext;
is good to know !For this particular scenario neither approach is good.
First approach returns second returns But I believe these are already specifics of BenchmarkDotNet.
I should probably learn more about Util class. Is there any API web page ? Or as I can see, there is already LINQPad Tutorial & Reference folder in Samples area. I should look there as a reference, right ?