Task

Write a program which uses a timer (with the least granularity available
on your system) to time how long a function takes to execute.

Whenever possible, use methods which measure only the processing time used
by the current process; instead of the difference in system time
between start and finish, which could include time used by
other processes on the computer.

This task is intended as a subtask for Measure relative performance of sorting algorithms implementations.




// 20210224 Rust programming solution
 
use rand::Rng;
use std::time::{Instant};
 
fn custom_function() {
 
   let mut i = 0;
   let mut rng = rand::thread_rng();
   let n1: f32 = rng.gen();
 
   while i < ( 1000000 + 1000000 * ( n1.log10() as i32 ) ) {
      i = i + 1;
   }
}
 
fn main() {
 
   let start = Instant::now();
   custom_function();
   let duration = start.elapsed();
 
   println!("Time elapsed in the custom_function() is : {:?}", duration);
}
 