3 ms·
About the first advice, if we’re talking about Rust, it might be a good idea to turn a number of assertions into debug_assert, so that it does not affect perfor
by baby 4y ago
About the first advice, if we’re talking about Rust, it might be a good idea to turn a number of assertions into debug_assert, so that it does not affect performance during prod. Of course it’s almost always not the case that you would want to not fail in prod, but sometimes you KNOW that an assert will HAVE TO be triggered in tests.
Another way to think about this is that there’s three kind of errors:
- recoverable (return Err)
- unrecoverable (debug assert)
- unrecoverable and tricky (assert)
- slashdev 4y agoAssertions are often free or nearly so. On modern out of order processors, it’s a fully predictable branch and a cheap assertion that nothing depends on. So the pipeline is unaffected and there’s usually a cheap test that often is completely free because there’s spare capacity. If the assert tests something expensive, I will usually switch to a debug assert.