diff --git a/Chapter09/Cargo.toml b/Chapter09/Cargo.toml index 7b7c7af..a0acf01 100644 --- a/Chapter09/Cargo.toml +++ b/Chapter09/Cargo.toml @@ -3,7 +3,6 @@ name = "Chapter9" version = "1.0.0" [dependencies] -cpuprofiler = "0.0.2" flame = "0.2" rand = "0.4.2" @@ -30,3 +29,7 @@ path = "performance_profiling2.rs" [[bin]] name = "performance_profiling3" path = "performance_profiling3.rs" + +[[bin]] +name = "performance_profiling4" +path = "performance_profiling4.rs" diff --git a/Chapter09/README.md b/Chapter09/README.md index aac2a37..a01c3cd 100644 --- a/Chapter09/README.md +++ b/Chapter09/README.md @@ -1,4 +1,4 @@ -This chapter makes use of Google's [cpuprofiler](http://goog-perftools.sourceforge.net/doc/cpu_profiler.html), -which needs to be installed separately. It will not be installed through the normal cargo build process. +This chapter makes use of Cargo Profiler and valgrind. +They will not be installed through the normal cargo build process and need separate installation. -[GPerftools](https://github.com/gperftools/gperftools) is also available on Github. +[Cargo Profiler](https://github.com/kernelmachine/cargo-profiler) installation instructions are available on Github. diff --git a/Chapter09/performance_profiling4.rs b/Chapter09/performance_profiling4.rs new file mode 100644 index 0000000..a800833 --- /dev/null +++ b/Chapter09/performance_profiling4.rs @@ -0,0 +1,23 @@ +fn a(n: u64) -> u64 { + if n>0 { + b(n); + b(n); + } + n * n +} + +fn b(n: u64) -> u64 { + c(n); + c(n); + n + 2 / 3 +} + +fn c(n: u64) -> u64 { + a(n-1); + a(n-1); + vec![1, 2, 3].into_iter().map(|x| x+2).sum() +} + +fn main() { + a(6); +}