I’ve made some measurements comparing performance of assert! and assert_eq! on part of the Rust’s own test suite (namely, tests in src/test).
First, I replaced all the assert!s with assert_eq!s where possible on branch assert1, then replaced all assert_eq!s with assert!s on branch assert2 (the difference is approximately 2350 assertions), then I measured the time spent on compiling and running the tests. Here’s the results:
assert1:
real 7m27.344s
user 0m0.885s
sys 0m2.306s
assert2:
real 7m19.202s
user 0m1.299s
sys 0m4.011s
assert1:
real 7m22.374s
user 0m1.143s
sys 0m4.053s
assert2:
real 7m20.605s
user 0m1.285s
sys 0m4.339s
assert1:
real 7m23.646s
user 0m1.219s
sys 0m4.116s
assert2:
real 7m19.442s
user 0m1.390s
sys 0m3.978s
On average, the slowdown from assert_eq! is about 1%, which is quite acceptable given that assert_eq! is much more useful when something actually breaks.
I’ll open a pull request replacing assert! with assert_eq! in tests.