use std::time::Instant; /** @return `msg` duplicated `n` times. */ fn string_times( n: u32, msg: &str ) -> String { let mut result_so_far: String = String::from(""); for _i in 0..n { result_so_far.push_str(msg); } result_so_far } fn main() { let mut v:Vec = Vec::new(); v[0] = b'a'; v[1] = b'z'; println!("{:?}", v); println!("Hello, world!"); println!("{}", string_times(3, "echo!")); for tst in vec![ ( 100,"a"), ( 1_000, "a"), ( 10_000, "a"), ( 100_000, "a"), ( 100, "abcde"), ( 1_000, "abcde"), ( 10_000, "abcde"), ( 100_000, "abcde"), (1_000_000, "abcde"), (1_000_000, "a"), (10_000_000, "abcde"), (100_000_000, "abcde"), ] { let k: u32 = tst.0; let msg: String = String::from(tst.1); let t0 = Instant::now(); string_times( tst.0, tst.1 ); let t1 = Instant::now(); println!( "{:>9}x{:>9} requires {:>9}ms.", k, msg.len(), t1.duration_since(t0).as_millis() ); } } // Want to say: the running-time of this function is O(n * msg.length()). /***************/