Function to avoid evaluation of assert condition

Version 1.0.1 (3,83 ko) par Dave Ober
After debugging code, this function enables developers to turn off the evaluation of assert conditions (if desired) to save CPU cycles.
3 téléchargements
Mise à jour 31 mai 2022

Afficher la licence

Have you ever wanted to turn off the evaluation of "expensive" assert conditions after you have completed debugging your code to save CPU Cycles? Well then assertF is the function for you.
It has minimal overhead and supports the same inputs (errID, msg, A1,...,An) as MATLAB's assert function. It utilizes a "persistent" assertFlag variable that allows developers to set the flag (at the start of code execution) and as long as the assert condition calls include a function handle "@()", then the condition is not evaluted if the assertFlag was set to false. However, if a developer wants the condition to always be evaluated inpendent of the assertFlag (like the MATLAB assert function), then exclude the function handle from the condition (or always include the assertFlag as the 2nd variable - although this adds a touch more overhead)
There are four files that help demonstrate how to effectively use this function.
assertF.m: The assert function that enables an assertFlag to determine if conditions with function handles are evaluated.
Test_AssertCallTimes.m: Example file that demonstrates how expensive condition calls using assertF compare with MATLAB's assert function and how much time is saved when the assertFlag is set to false for the same conditions. This file also shows how to use assertF with and without function handles. To get accurate evaluation times we use MATLAB's timeit function.
Test_AssertFalseCases.m: Example file that has six different condition cases that are all false (and throw errors) and are caught in a try/catch block.
AssertFalseCase.m: The six cases called by Test_AssertFalseCases.m

Citation pour cette source

Dave Ober (2026). Function to avoid evaluation of assert condition (https://fr.mathworks.com/matlabcentral/fileexchange/111865-function-to-avoid-evaluation-of-assert-condition), MATLAB Central File Exchange. Extrait(e) le .

Compatibilité avec les versions de MATLAB
Créé avec R2022a
Compatible avec les versions R2008a et ultérieures
Plateformes compatibles
Windows macOS Linux
Tags Ajouter des tags
Version Publié le Notes de version
1.0.1

Fixed grammar mistake in description

1.0.0