question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic `OperationsPerInvoke`

See original GitHub issue

I load a list of strings externally as data for my benchmarks. My goal is to measure average time for me to process one string. Of course the data is loaded before benchmarking, but since it happens at runtime, I cannot supply OperationsPerInvoke attribute param to BenchmarkAttribute, which requires compile-time constant. Is there a way around?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:26 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
lipchevcommented, May 9, 2021

As a workaround- I’ve resorted to using a Source Generator that creates a class named BenchmarkConstants where I have all of the dynamically calculated stuff (like the size of my Enums) placed as constants.

1reaction
adamsitnikcommented, Nov 20, 2017

My initial idea was:

[Benchmark]
public int CompressA() => magic();

[ExtraResults(nameof(CompressA))]
public IDictionary<string, string> ExtraDataA()
    => new Dictionary<string, string>()
    {
        { "benchAcompressSize", CompressA().ToString() },
        { "anotherInterestingThing", "itsValue" }
    };

this extra method would be executed once, after stoping the watch, before last iteration/global cleanup. Then serialized and available in the results, so people could use sth like this in the columns:

public class MyColumn : IColumn
{
   public string GetValue(Summary summary, Benchmark benchmark) 
    => summary.ExtraResults[benchmark].GetValue("theKey");
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

DynamicObject.TryInvoke(InvokeBinder, Object[], ...
Provides the implementation for operations that invoke an object. Classes derived from the DynamicObject class can override this method to specify dynamic ......
Read more >
powerful benchmarking in .net
profiling") is a form of dynamic program analysis that measures, for example, the space (memory) or time complexity ... [Benchmark(OperationsPerInvoke = 4)].
Read more >
Benchmarking and Exploring C#'s Dynamic Keyword
Today I wanted to explore and benchmark a C# feature that I've never used before, the dynamic type. Dynamic v. Static Type Systems....
Read more >
Custom and not-constant "Operations per invocation" (Re
operationsPerInvocation (...) to match your .params(...) if you want to normalize the operations like that. > Looks like "@AuxCounters" is ...
Read more >
How to use JMH properly? Example with ArrayList
Also the notion of operation can be "altered" with @OperationsPerInvocation - which is another sharp tool.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found