title: How to use <chrono> in order to see how much time a function took to execute
body: <p>I have to compare the time differentiation between bubble sort, selection sort, linear search, and binary search functions. I have already completed all of my functions, but every time I display execution time, it displays a 0. Anyway around this, or do I have to change something about my formatting... My time display starts at the end of case 1. I did not include my other functions into this example.</p>
  
  <pre><code>using namespace std;
  using std::time;
  using namespace std::chrono;
  
  int Menu(); // Menu for sorting and search options.
  void bubbleSort(int [], int); // Applies bubble sort algorithm to sort the elements of an unsorted array
  void selectionSort(int [], int); // Applies selection sort algorithm to sort the elements of an unsorted array
  int linearSearch(int [], double[], int, int ); // Applies the linear search algorithm to search for book ID
  int binarySearch(int [], double [], int, int); // Applies the binary search algorithm to search for book ID
  void display(string [], int [], double [], int); // To display the contents of parallel array in a tabular format
  
  
  
  int main()
  {
  
      int size = 10, choice, searchKey, searchKey2, result, result2, quantity=0, quantity2=0;
      const int SIZE = 1000; // Constant max for number of numbers random number generator will output
      const int MAXRANGE = 500; // Constant range for the range of numbers random number generator will sort through
      int selectionsort[ SIZE ] = {0};
      int bubblesort[ SIZE ] = {0};
      time_t t;
      srand((unsigned) time(&amp;t));
  
  
      string bookTitle[] = {"Starting out with C++", "Java Programming", "Software Structures",
      "Design and Analysis of Algorithms", "Computer Graphics", "Artificial Intelligence: A Modern Approach",
      "Probability and Statistics", "Cognitive Science", "Modern Information Retrieval", "Speech and Language Processing"};   // Parallel Arrays
  
      int bookID[] = {1101, 1211, 1333, 1456, 1567, 1642, 1699, 1755, 1800, 1999};
  
      double bookPrice[] = {112.32, 73.25, 54.00, 67.32, 135.00, 173.22, // Use of parallel arrays to match data with book ID and price
      120.00, 42.25, 32.11, 123.75};
  
  
  
      while (choice != 5) // Loops as long as user does not enter 5
      {
          choice = Menu();
          if (choice == 5){
           cout &lt;&lt; "Thanks for stopping by! Please, do come again soon :)";   break;} // Program terminates if user enters 5
          switch (choice)
          {
          case 1:
              display(bookTitle, bookID, bookPrice, size); // Displays book title, ID, and price using arrays
              cout &lt;&lt; "***LINEAR SEARCH***" &lt;&lt; endl;
              cout &lt;&lt; "Please enter a book ID to purchase: ";
              cin &gt;&gt; searchKey;
              result = linearSearch(bookID, bookPrice, size, searchKey);
              if (result &gt;=0){ // Searches in the array for value user enters, this way it will find the price of each book.
  
                  cout &lt;&lt; "The book " &lt;&lt; bookTitle[result] &lt;&lt; " was chosen." &lt;&lt; endl;
                  cout &lt;&lt; "Please enter how many you would like to purchase: ";
              result = linearSearch(bookID, bookPrice, size, searchKey);
                  cin &gt;&gt; quantity; // Quantity used in order to count number of books using the array the user wishes to purchase.
                  cout &lt;&lt; "You have purchased " &lt;&lt; quantity &lt;&lt; " " &lt;&lt; bookTitle[result] &lt;&lt; endl &lt;&lt; "For the total price of $" &lt;&lt; bookPrice[result] * quantity &lt;&lt; endl;
                  cout &lt;&lt; "Thank you for your business!" &lt;&lt; endl &lt;&lt; endl;
                  high_resolution_clock::time_point t1 = high_resolution_clock::now();
                  linearSearch(bookID, bookPrice, size, searchKey);
                  high_resolution_clock::time_point t2 = high_resolution_clock::now();
  
                  auto duration = duration_cast&lt;microseconds&gt;( t2 - t1 ).count();
  
                  cout &lt;&lt; "The time the process took is " &lt;&lt; duration &lt;&lt; " milliseconds" &lt;&lt; endl &lt;&lt; endl;
              }
  </code></pre>