Is there a way to get benchmark arguments from GlobalSetup for currently running benchmark? #2827
Replies: 3 comments 1 reply
-
Can you explain what you're trying to do? Fields assigned in GlobalSetup are usable in the benchmark, just read the field directly instead of trying to pass it in as an argument. ArgumentsSource, however, does not interact with GlobalSetup (and tbh it should be static to make that more obvious). See #1408 |
Beta Was this translation helpful? Give feedback.
-
My benchmarks use a large set of complex objects as argument values. The objects are constructed from data stored as files. Creating all objects at once (in a method that is referenced by ArgumentsSource) for every benchmark run is pretty time and resource consuming. So what I want to implement:
So now it is not possible to access current benchmark argument values before work delegate is called (to which they are indeed passed). |
Beta Was this translation helpful? Give feedback.
-
It works! Appreciate it, thank you! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have already looked through issues and discussions but found nothing relevant so far.
The problem is that there are no legal means to get argument from inside
Setup
method when current benchmark is running.What am I looking for is following:
I have a workaround though, but it involves reflection performed on generated benchmarker code - it traverses
Runnable_
constructor IL code and extracts required data. The workaround fits well for my needs but it's poorly maintainable and smells horribly.Beta Was this translation helpful? Give feedback.
All reactions