title: How to count the total number of (CPU cycles) and (instructions retired) during the execution of the program?
body: <p>I program with C++ on Linux.</p>
  
  <p>I have several competitor programs that performs the same tasks but in the different ways.</p>
  
  <p>I want to compare those systems against mine in terms of CPU cycles spend and the number of instructions retired.</p>
  
  <p>How to count the total number of (CPU cycles) and (instructions retired) during the execution of the program?</p>
  
  <p>Do I need to access any hardware counter? or is there any well-known method to achieve it?</p>