diff --git a/examples/rtt_timing.rs b/examples/rtt_timing.rs index 4ee67756ac0d8fceb17692d8701abfa5df55fba9..72fbb09d39f1253d554f1e86e53a1fd5c49575e7 100644 --- a/examples/rtt_timing.rs +++ b/examples/rtt_timing.rs @@ -60,37 +60,57 @@ fn timed_loop() -> (u32, u32) { // ------------------------------------------------------------------------ // Exercises: // +// start 2987, end 4793139, diff 4790152 +// // A.1) What is the cycle count for the loop? // > cargo run --example rtt_timing // // [Your answer here] +// 2987 // // A.2) How many cycles per iteration? // // [Your answer here] +// 4790152 // // A.3) Why do we need a wrapping subtraction? // // [Your answer here] +// If end value has wrapped around then start > end. Thus we need to wrap around when we subtract so we get the correct difference value. // // ------------------------------------------------------------------------ // Now try a release (optimized build, see `Cargo.toml` for build options). // B.1) What is the cycle count for the loop? // > cargo run --example rtt_timing --release // +// start 30305915, end 30375916, diff 70001 +// // [Your answer here] +// 30305915 // // B.2) How many cycles per iteration? // // [Your answer here] +// 70001 // // What is the speedup (A/B)? // // [Your answer here] +// 4790152 / 70001 = 68.4297652891 +// // // Why do you think it differs that much? // // [Your answer here] +// I think that the optimizer removed the for loop: +// for _ in 0..10000 { +// asm::nop(); +// } +// Thus the end variable is set right after the start variable. This makes the time difference very +// small. But it is not near 10000 time faster because the function DWT::get_cycle_count() is much +// slower at getting the cycle count then it is to run one iteration of the loop. +// +// // // ------------------------------------------------------------------------ // In the loop there is just a single assembly instruction (nop). @@ -112,15 +132,20 @@ fn timed_loop() -> (u32, u32) { // C.1) What is the cycle count for the loop? // > cargo run --example rtt_timing --release --features nightly // +// start 1356808538, end 1356848539, diff 40001 +// // [Your answer here] +// 1356808538 // // C.2) How many cycles per iteration? // // [Your answer here] +// 40001 // // What is the speedup (A/C)? // // [Your answer here] +// 4790152 / 40001 = 119.75080623 // // ------------------------------------------------------------------------ // D) Now lets have a closer look at the generated assembly.