The Timer Class

Published on Thursday, May 05 2016 • less than a minute read


This semester, according to our syllabus, we have the 'Design and Analysis of Algorithms' subject. The theory classes contain core algorithmic topics like divide - and - conquer, greedy technique and dynamic programming and in labs, we solve problems using said techniques. Typically, schools and colleges use Turbo C++, distributed by Borland, which we run under an emulated environment like DOSBOX because of  the deprecation of MS-DOS and surge of the Windows NT line of Operating Systems. However, we should clearly not ignore the alternatives out there. We still have to code the solution for the old Turbo C++ compiler from the 90s. I have created a repo on GitHub for solutions to the different problems in our syllabus (for MS-DOS, NT  - Visual C++ Compiler and Linux - g++) We are supposed to implement the given problem using the appropriate technique and we are to monitor the order of growth of said algorithm. In DOS, we use a Timer class that is present in the Template Class Library. By default, the include folder does not reference the Template Class Library, but this can be done pretty easily using the Settings Tab in Turbo C++. The problem is that the Timer class runs only on DOS, so clearly we need a simple Timer Class Implementation for Linux and Visual C++. I have gone and done just that. My implementation provides minimal functionality

  1. Starting a Timer
  2. Stopping a Timer (Pause)
  3. To Reset the Timer that makes it ready to use again
  4. To return the time that passed between the function calls to start and stop

The Visual C++ contains classes in the std::chrono namespace which I've used in my Timer implementation for Windows. For Linux, we use the ctime header file and the clock function. The link to the repository: https://github.com/sauravMSFT/Design-Analysis-Algorithms In the next post, I'd like to talk about adding paths to the gcc and g++ environment variables on linux and maybe how to run gcc and g++ on Windows.