Name

assert_benchfun — Benchmarks a function and measure its performance.

Calling Sequence

   

Parameters

fun :

a function, the function to be executed

iargs :

a list, the list of input arguments for the function (default iargs=list())

nlhs :

a 1 x 1 matrix of floating point integers, the number of output arguments of the function (default nlhs=1)

kmax :

a 1 x 1 matrix of floating point integers, the number of executions (default kmax=10)

verbose :

a 1x1 matrix of booleans, set verbose = %t to display the message (default verbose=%f)

t :

a kmax x 1 matrix of doubles, the system times, in seconds, required to execute the function

msg :

a 1 x 1 matrix of strings, a message summarizing the benchmark

Description

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 optional input argument equal to the empty matrix is replaced by its default value.

Examples

function c = pascalup_col (n)
// Pascal up matrix.
// Column by column version
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
endfunction
// Prints the message
assert_benchfun ( pascalup_col , list(100) , [] , [] , "pascalup_col" , %t );
// Basic call
[t,msg] = assert_benchfun ( pascalup_col , list(100) )
mprintf("pascalup_col: %s\n",msg);
// Customize the number of runs
[t,msg] = assert_benchfun ( pascalup_col , list(100) , [] , 15 )
// Customize the message
[t,msg] = assert_benchfun ( pascalup_col , list(100) , [] , 15 , "pascalup_col" )

// Test sin (this is a primitive)
assert_benchfun ( sin , list(ones(100,100)) , 1 , 15 , "sin" , %t );

// Bench a function with 2 output arguments
function [a,b] = testfun ()
a = ones(10,10)
b = zeros(10,10)
endfunction
[t,msg]=assert_benchfun ( testfun , [] , 2 , 15 , "testfun" , %t );

// Bench a function with 2 input arguments
function y = testfun2 ( m , n )
y = zeros(m,n)
endfunction
[t,msg]=assert_benchfun ( testfun2 , list(11,12) , [] , [] , "testfun2" , %t );

   

Authors

2010 - DIGITEO - Michael Baudin