Benchmarking TF1 integration time

Would be this code good for benchmarking TF1::Integral?

    start = std::chrono::high_resolution_clock::now();
    double integral = Normal.Integral(x_low,x_up);
    stop = std::chrono::high_resolution_clock::now();
    time = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
    std::cout << "Integration Time 2:\t" << time.count() << '\n' << integral << '\n';

The code looks fine to me to benchmark the integration time. You might need to consider also the time to construct the TF1 object in case you cannot move it outside your critical code


The use case here would be building an efficient numerical integrator. With this method of benchmarking I’ve managed to get to 1/10 the time of TF1::Integral with equal/more precision (given the integration interval is sufficiently small). I was not sure of the reliability of this code.

Integrating: From: -1 to 1 Integration Time 1: 3816 3.365883939231586033163576288096408006822457537055 Integration Time 2: 68412 3.3658839392315860195026289147790521383285522460938 Error 1: -6.5052130349130266040447168052196502685546875e-18 Error 2: 7.15573433840432926444918848574161529541015625e-18

This would an output example of integration of “2*cos(x)”. Integral 1 is my integrator integral 2 is TF1::Integral.

Instead of TF1 which is not super efficient, you can use directly the Integrator class and construct the class outside your benchmark. This will reflect better the time of integration.
See the code of TF1::IntegralOneDim (ROOT: hist/hist/src/TF1.cxx Source File).
The overhead of using TF1 will be more visible when integrating simple functions. Note also that there are different integration methods available. See ROOT: TF1 Class Reference


1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.