Decorators · 7.3
@benchmark
All lessons are open — jump whenever you need.
@benchmark measures execution time:
@benchmark
fn heavy_computation() -> int {
let mut sum = 0
for i in 0..1000000 {
sum = sum + i
}
return sum
}
print(heavy_computation())
// [benchmark] heavy_computation: 12msGoal: Add @benchmark to a function that computes the sum from 1 to 1,000,000.
lesson-7-3.zolo
Program output
Run the code to see the output