The Integration gem now includes quite a few functions from which to
choose. To make this choice easier, I have done some benchmarking to
see how fast and acuurate each of these functions are. The results of
these tests for some randomly chosen functions are given below. The
speed test reports shows the user CPU time, system CPU time, the sum
of the user and system CPU times, and the elapsed real time to perform
100 iterations of the code. The unit of time is seconds.
For function f(x)= x2+3*x+7 on interval (0,1)
Speed Tests
123456789101112131415161718192021222324252627
Benchmarking with 100 iterations
user system total real
rectangle 72.040000 0.010000 72.050000 ( 72.058014)
user system total real
trapezoid 105.500000 0.000000 105.500000 (105.489225)
user system total real
simpson 0.020000 0.000000 0.020000 ( 0.017601)
user system total real
romberg 0.000000 0.000000 0.000000 ( 0.002219)
user system total real
adaptive_quadrature 0.010000 0.000000 0.010000 ( 0.002757)
user system total real
gauss 0.010000 0.000000 0.010000 ( 0.006439)
user system total real
gauss_kronrod 0.000000 0.000000 0.000000 ( 0.008615)
user system total real
simpson3by8 0.080000 0.000000 0.080000 ( 0.074791)
user system total real
boole 0.100000 0.000000 0.100000 ( 0.100300)
user system total real
open_trapezoid 181.470000 0.050000 181.520000 (181.572745)
user system total real
milne 0.060000 0.000000 0.060000 ( 0.058677)
user system total real
qng 0.000000 0.000000 0.000000 ( 0.003788)
user system total real
qag 0.010000 0.000000 0.010000 ( 0.010407)
For function f(x) = x5+7*x2+2*cos(x) on interval (0,1)
Speed Tests
123456789101112131415161718192021222324252627
Benchmarking with 100 iterations
user system total real
rectangle 534.790000 0.510000 535.300000 (538.238675)
user system total real
trapezoid 835.950000 0.540000 836.490000 (839.233313)
user system total real
simpson 0.650000 0.000000 0.650000 ( 0.652694)
user system total real
romberg 0.010000 0.000000 0.010000 ( 0.002073)
user system total real
adaptive_quadrature 0.170000 0.000000 0.170000 ( 0.167520)
user system total real
gauss 0.000000 0.000000 0.000000 ( 0.007621)
user system total real
gauss_kronrod 0.020000 0.000000 0.020000 ( 0.010610)
user system total real
simpson3by8 0.820000 0.000000 0.820000 ( 0.831039)
user system total real
boole 0.120000 0.000000 0.120000 ( 0.119929)
user system total real
open_trapezoid 1019.100000 0.150000 1019.250000 (1020.034828)
user system total real
milne 0.980000 0.000000 0.980000 ( 0.970671)
user system total real
qng 0.000000 0.000000 0.000000 ( 0.008263)
user system total real
qag 0.020000 0.000000 0.020000 ( 0.020050)
If you are keen to test any function of your choice you can pull from
my Integration gem fork
and change the files in the benchmark folder. For both the files,
accuracy.rb and speed.rb, change the line func = lambda{|x| f(x)}
with f(x) as your desired function. In case you want to perform
accuracy benchmarks, make sure that you know the exact result of the
integration operation before hand and assign this value to the
variable actual_result Feel free to comment if you face any problem
running the benchmarks with your desired functions.