MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / main

Function main

code/chapter02/static_func_call2.rs:9–28  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7}
8
9fn main() {
10 let ns: [i64; 3] = [100000, 5000000, 1000000];
11 let mut nanos = [0, 0, 0, 0, 0];
12 for &num in ns.iter() {
13 for i in 0..5 {
14 let now = SystemTime::now();
15 let _sum = sum_of_n(num);
16 let duration = now.elapsed().unwrap();
17 nanos[i] = duration.as_nanos() as i32;
18 }
19
20 let mut nanos_sum = 0;
21 for &nano in nanos.iter() {
22 nanos_sum += nano;
23 }
24
25 let time = nanos_sum/(nanos.len() as i32);
26 println!("func used {time} ns");
27 }
28}

Callers

nothing calls this directly

Calls 3

sum_of_nFunction · 0.70
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected