ProgressTracker

The ProgressTracker is a quite handy tool for evaluating the performance of some processing or tasks.

fn run() {
  var txtReader = TextReader::new("./data.txt");
  var tracker = ProgressTracker{
    start: time::now(),
    total: txtReader.available(),
  };
  while(txtReader.available()>0) {
    var line = txtReader.readLine();
    //process the line
    tracker.update((tracker.total - txtReader.available()));
  }
}

In the above example, a tracker is set to monitor the progress of a text file processing. The start time is initialized to time::now(), and the total set to the size of the file to process. Setting the total is not mandatory, but activates the compuation of the progress and of the estimated remaining time of process.
The update method updates the quantity processed so far to notify the progress. The ProgressTracker uses this information to compute the throughput (number of elements processed per second), and update the percentage of progress and estimated time for completion.
The ProgressTracker can be consulted (printed) at regular interval to monitor the progress. We suggest not printing every update, but rather trigger the print at regular intervals of progress, time, etc. to avoid degrading the performances of the main loop.

The ProgressTracker will provide the following information:

type ProgressTracker {
  start: time;          //Time when the process has been started
  total: int?;          //Total number of element to process
  counter: int?;        //Current number of element processed (update)
  duration: duration?;  //Time currently elapsed since the start of the process
  progress: float?;     //Overall progress between 0 (0%) => 1 (100%), available only if total is set 
  speed: float?;        //Throughput of the last update (difference in elements / difference in time)
  remaining: duration?; //Expected time to complete, only available if total is set
}