Pure Programmer
Blue Matrix


Cluster Map

Project: CurrentTimeMilliseconds

Often it is necessary to time how long a section of code takes to execute to get useful information for optimization. Write a program that computes squares between 1 and 10,000 and prints them. Time how long it takes to perform this function to milliseconds resolution.

Output
$ rustc CurrentTimeMilliseconds.rs error: unknown format trait `d` --> CurrentTimeMilliseconds.rs:12:31 | 12 | println!("{}", format!("{0:d}^2 = {1:d}", x, x * x)); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `d` --> CurrentTimeMilliseconds.rs:12:41 | 12 | println!("{}", format!("{0:d}^2 = {1:d}", x, x * x)); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error: unknown format trait `d` --> CurrentTimeMilliseconds.rs:17:39 | 17 | println!("{}", format!("Duration: {0:d} ms", stop - start)); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error[E0425]: cannot find function `clock_millis` in this scope --> CurrentTimeMilliseconds.rs:8:22 | 8 | let mut start:i64 = clock_millis(); | ^^^^^^^^^^^^ not found in this scope error[E0425]: cannot find function `clock_millis` in this scope --> CurrentTimeMilliseconds.rs:16:21 | 16 | let mut stop:i64 = clock_millis(); | ^^^^^^^^^^^^ not found in this scope error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0425`.

Solution