Main Content

coder.performance.Benchmarkable

Input and output information of generated code

Since R2024b

    Description

    A Benchmarkable object contains input and output information of generated code that you can use for rerunning coder.timeit without regenerating code. It is useful for measuring execution times across multiple input sets.

    To create a coder.performance.Benchmarkable object, use the coder.timeit function.

    Properties

    expand all

    Output of the generated code, specified as a cell array.

    Input arguments used by codegen to generate the code, specified as a cell array.

    Configurations used to generate code, specified as a coder.MexCodeConfig or coder.EmbeddedCodeConfig object.

    Name of the wrapper created for timing the input function, specified as a character vector.

    Object Functions

    runMeasure execution time of function without regenerating code

    Examples

    collapse all

    Generate code without executing the timing function and times the function for multiple sets of inputs using the generated code.

    Define the MATLAB® function filterSignal.

    function out = filterSignal(a,b,x)
        out = filter(a,b,x);
    end

    Define compile-time input arguments and generate code with the coder.timeit function using the generatecodeonly option. The coder.timeit function creates a wrapper object that you can use to measure the execution time of the generated code with different input arguments.

    a = [1 1];
    b = [2 2];
    x = 1:1e7;
    
    [~,~,bObj] = coder.timeit("filterSignal",1,{a,b,x},"generatecodeonly", ...
                                        CompileArgs={a,b,coder.typeof(x, [1 Inf])})
    coder_timeit INFO: Generating code and building MEX.
    
    bObj = 
      Benchmarkable with properties:
    
        CompileArguments: {[1 1]  [2 2]  [1×1 coder.PrimitiveType]}
             CoderConfig: [1×1 coder.MexCodeConfig]
                    Name: 'filterSignalTestWrapper'
    
    

    Measure the execution time of the generated code for different input values.

    t1 = run(bObj,a,b,1:1e4)
    coder_timeit INFO: Running MEX.
    TimingResult with 6068 Runtime Sample(s)
    
    Statistical Overview:
       mean = 8.24e-05 s    max = 4.35e-04 s     sd = 9.31e-06 s
     median = 8.00e-05 s    min = 7.88e-05 s   90th = 8.69e-05 s
    
    t1 = 
    8.0000e-05
    
    t2 = run(bObj,a,b,1:1e7)
    coder_timeit INFO: Running MEX.
    TimingResult with 10 Runtime Sample(s)
    
    Statistical Overview:
       mean = 1.13e-01 s    max = 1.23e-01 s     sd = 5.35e-03 s
     median = 1.11e-01 s    min = 1.07e-01 s   90th = 1.22e-01 s
    
    t2 = 
    0.1114
    
    t = table([1e4; 1e7],[t1; t2],'VariableNames',{'Size','Runtime (s)'})
    t=2×2 table
        Size     Runtime (s)
        _____    ___________
    
        10000       8e-05   
        1e+07      0.1114   
    
    

    Version History

    Introduced in R2024b