calling system clock?

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2006
Posts: 1,169
Reputation: Duki has a spectacular aura about Duki has a spectacular aura about Duki has a spectacular aura about 
Solved Threads: 9
Duki's Avatar
Duki Duki is offline Offline
Veteran Poster

calling system clock?

 
0
  #1
Oct 22nd, 2007
Hey guys,

we were given an opportunity for extra credit in my OOP class. We're going over recursion and my prof said if we could do a project using recursion and do another useing iterative statments, and time them, we would be given extra cred.

Is there a way to call the system clock at the begining of the loop and at the end; then subtract the 1st from the 2nd? Is there an easier way than this?
It is practically impossible to teach good programming style to students that have had prior exposure to Basic; as potential programmers they are mentally mutilated beyond hope of regeneration.

-Edsger Dijkstra
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 62
Reputation: Ptolemy is an unknown quantity at this point 
Solved Threads: 8
Ptolemy's Avatar
Ptolemy Ptolemy is offline Offline
Junior Poster in Training

Re: calling system clock?

 
0
  #2
Oct 22nd, 2007
You can use the standard time library to do it, sort of:
  1. #include <ctime>
  2. #include <iostream>
  3.  
  4. void long_running_operation()
  5. {
  6. for ( unsigned i = 1; i != 0; i++ )
  7. ;
  8. }
  9.  
  10. int main()
  11. {
  12. std::clock_t start;
  13. std::clock_t end;
  14.  
  15. std::cout<<"Beginning timer..."<<std::endl;
  16. start = std::clock();
  17.  
  18. long_running_operation();
  19.  
  20. end = std::clock();
  21. std::cout<<"The operation took "
  22. << ( double ( end ) - start ) / CLOCKS_PER_SEC
  23. <<" seconds\n";
  24. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 1,169
Reputation: Duki has a spectacular aura about Duki has a spectacular aura about Duki has a spectacular aura about 
Solved Threads: 9
Duki's Avatar
Duki Duki is offline Offline
Veteran Poster

Re: calling system clock?

 
0
  #3
Oct 25th, 2007
awesome thanks!
It is practically impossible to teach good programming style to students that have had prior exposure to Basic; as potential programmers they are mentally mutilated beyond hope of regeneration.

-Edsger Dijkstra
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC