Best practices to use Matlab assert

6 visualizaciones (últimos 30 días)
Hari Krishna Nalla
Hari Krishna Nalla el 31 de Mayo de 2021
Comentada: Bruno Luong el 1 de Jun. de 2021
Hi,
In my project, i'm using 'assert' checks in many places in the code.
I would like to understand how it impacts he runtime? Does it has any overhead similar to traditional programming languages like C in debug mode.
Thanks,
Hari
  2 comentarios
Stephen23
Stephen23 el 31 de Mayo de 2021
"In my project, i'm using 'assert' checks in many places in the code."
Then using ASSERT is the right thing to do: much better than code that fails badly without explanation.
"Does it has any overhead similar to traditional programming languages like C in debug mode."
No, the ASSERT itself is most likely going to require only a very small part of the total runtime.
Bruno Luong
Bruno Luong el 1 de Jun. de 2021
Other alternative to assert is arguments block

Iniciar sesión para comentar.

Respuestas (1)

Bruno Luong
Bruno Luong el 31 de Mayo de 2021
No C debug mode slows every statement down. ASSERT costs the overhead of checking whatever you instruct MATLAB to check.
It matter or not depends on the percentage of that overhead wrt to the rest of the code.

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by