Load Test - Releasing causes a stack overflow. Why is there no bench for cargo?

When trying to write an optimized DSP algorithm, I was interested to know the relative speed between the stack distribution and the heap distribution and the size limitations of the arrays distributed over the stacks. I understand that there is a restriction on the size of the stack frames, but I don’t understand why the following runs, generating apparently realistic test results with cargo bench, but with an error when starting with cargo test --release.

#![feature(test)]
extern crate test;

#[cfg(test)]
mod tests {
    use test::Bencher;

    #[bench]
    fn it_works(b: &mut Bencher) {
        b.iter(|| { let stack = [[[0.0; 2]; 512]; 512]; });
    }
}
+6
source share
1 answer

, , 8 × 2 × 512 × 512 = 4 .

cargo test, cargo bench , "" it_works() , "" .

8 MiB, . , , .

, , . Linux 2 MiB, . , 4 MiB /segfault.

RUST_MIN_STACK.

$ RUST_MIN_STACK=8388608 cargo test 

cargo test , , .

- , . (box it), static mut.

+11

Source: https://habr.com/ru/post/1015938/


All Articles