Benchmarks a function and measure its performance.
[t,msg] = scibench_benchfun ( fun ) [t,msg] = scibench_benchfun ( fun , name ) [t,msg] = scibench_benchfun ( fun , name , kmax ) [t,msg] = scibench_benchfun ( fun , name , kmax , verbose ) [t,msg] = scibench_benchfun ( fun , name , kmax , verbose , outfun )
a function or a list, the function to be executed. If fun is a list, the first element is expected to be a function and the remaining elements of the list are input arguments of the function, which are appended at the end.
a 1 x 1 matrix of strings, the name of the function to be executed (default name="").
a 1 x 1 matrix of floating point integers, the number of executions, must be greater than 1 (default kmax=10).
a 1x1 matrix of booleans, set to %t to display the result (default verbose = %t)
a function or a list, the output function (default is an empty output function). If outfun is a list, the first element is expected to be a function and the remaining elements of the list are input arguments of the function, which are appended at the end.
a kmax x 1 matrix of doubles, the system times, in seconds, required to execute the function
a 1 x 1 matrix of strings, a message summarizing the benchmark
This function is designed to be used when measuring the performance of a function. It uses the timer function to measure the system time. The function is executed kmax times and the performance is gathered into the matrix t. The message summarizes the test and contains the mean, min and max of the times.
Any argument equal to the empty matrix [] is replaced by its default value.
The header of the function fun must be
where t measures the time to perform the task (in seconds).It might happen that the function requires additionnal arguments to be evaluated. In this case, we can use the following feature. The function fun can also be the list (f,a1,a2,...). In this case f, the first element in the list, must have the header:
where the input arguments a1, a2, ... will be automatically be appended at the end of the calling sequence.The output function outfun should have header
where k is the simulation index and t is the time required to perform the run. Here, stop is a boolean, which is %t if the algorithm must stop.It might happen that the output function requires additionnal arguments to be evaluated. In this case, we can use the following feature. The function outfun can also be the list (outf,a1,a2,...). In this case outf, the first element in the list, must have the header:
where the input arguments a1, a2, ... will be automatically be appended at the end of the calling sequence.// // An example with 0 input argument function t=pascalup_col0rhs() // Pascal up matrix. // Column by column version tic () n = 100 c = eye(n,n) c(1,:) = ones(1,n) for i = 2:(n-1) c(2:i,i+1) = c(1:(i-1),i)+c(2:i,i) end t = toc() endfunction [t,msg] = scibench_benchfun ( pascalup_col0rhs ); [t,msg] = scibench_benchfun ( pascalup_col0rhs , "pascalup_col" ); // // An example with 1 input argument function t=pascalup_col(n) // Pascal up matrix. // Column by column version tic () c = eye(n,n) c(1,:) = ones(1,n) for i = 2:(n-1) c(2:i,i+1) = c(1:(i-1),i)+c(2:i,i) end t = toc() endfunction [t,msg] = scibench_benchfun ( list(pascalup_col,100) , "pascalup_col" ); [t,msg] = scibench_benchfun ( list(pascalup_col,100) , "pascalup_col" , 10 ); [t,msg] = scibench_benchfun ( list(pascalup_col,100) , "pascalup_col" , 10, %f ) // // Use a callback to print the timings function stop=myoutfun(k, t) stop = %f mprintf("Run #%d, t=%.2f\n",k,t) endfunction scibench_benchfun ( list(pascalup_col,100) , "pascalup_col" , [] , [] , myoutfun ); | ![]() | ![]() |