我正在编写一个计算量很大的程序,并且在调试模式下运行起来非常慢 .
我的程序也受到整数溢出的困扰,因为我从 u8 数组读取数据,并且 u8 类型通过类型推断传播到意外的位置,而Rust更喜欢溢出而不是将整数提升为更大的类型 .
u8
在发布模式下构建会禁用溢出检查:
cargo run --release
如何通过优化和运行时溢出检查来构建Rust可执行文件?
您可以在发布模式下编译with overflow checks enabled:
[profile.release] overflow-checks = true
这将 -C overflow-checks=true 传递给编译器 . 在早期版本的Rust中, overflow-checks 是 debug-assertions 开关的一部分,因此在某些情况下您可能需要使用它 .
-C overflow-checks=true
overflow-checks
debug-assertions
其他时候,最简单的事情可能是build in test or dev mode with optimizations:
[profile.dev] opt-level = 3
1 回答
您可以在发布模式下编译with overflow checks enabled:
这将
-C overflow-checks=true
传递给编译器 . 在早期版本的Rust中,overflow-checks
是debug-assertions
开关的一部分,因此在某些情况下您可能需要使用它 .其他时候,最简单的事情可能是build in test or dev mode with optimizations: