January 2019
Intermediate to advanced
520 pages
14h 32m
English
Rust supports benchmark testing out of the box. You can use it to compare the performance of different solutions of the same problem or to get to know the time of execution of some parts of your application.
To use benchmarks, you have to add a function with the #[bench] attribute. The function expects a mutable reference to the Bencher instance. For example, let's compare cloning a String with taking a reference to it:
#![feature(test)]extern crate test;use test::Bencher;#[bench]fn bench_clone(b: &mut Bencher) { let data = "data".to_string(); b.iter(move || { let _data = data.clone(); });}#[bench]fn bench_ref(b: &mut Bencher) { let data = "data".to_string(); b.iter(move || { let _data = &data; });}
To benchmark, you have ...
Read now
Unlock full access