rapidcheck icon indicating copy to clipboard operation
rapidcheck copied to clipboard

Use rapidcheck with nonius benchmark

Open mohnishkodnani opened this issue 9 years ago • 2 comments

Hi, I am trying to benchmark the performance of one of the functions. I want to test it against lots of different string inputs. For that I wanted to use the generator for strings. However when I try to use the generator, I always get operator* is not allowed in the context error. Ex:

#include "rapidcheck.h"
NONIUS_BENCHMARK("benchmark tokenizer", [](){
   const auto str = *rc::gen::nonEmpty(rc::gen::string<std::string>());

})

Is there a way to set context for the generator ?

mohnishkodnani avatar Jul 15 '16 07:07 mohnishkodnani

You probably don't want to use operator* at all in this case. If you look at Gen.h you can see that it's also a function object that takes a Random object and the size to generate at. If you call that with some appropriate arguments (you can look at Random.h to see how you create random engines and then also just pick a size, preferably in the range [0, 100]), you'll get back a Shrinkable<T> where T is the generated type. You won't get the actual value until you call the .value() method on that object. You can also get the possible shrinks of that value by calling the .shrinks() method.

emil-e avatar Jul 15 '16 07:07 emil-e

Thanks very much for your prompt and very helpful tip. If I use rc::gen:resize say for example const auto nonEmptyStrGen = rc::gen::resize(109600, rc::gen::nonEmpty(rc::gen::string<std::string>())); and then create shrinkables

        const auto shrinkable_gen = nonEmptyStrGen(random.next(), 100);
        const auto doc = shrinkable_gen.value();

Is there some estimate as to the size of the strings being generated.

mohnishkodnani avatar Jul 15 '16 08:07 mohnishkodnani