| | |
calling system clock?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
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?
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
-Edsger Dijkstra
You can use the standard time library to do it, sort of:
C++ Syntax (Toggle Plain Text)
#include <ctime> #include <iostream> void long_running_operation() { for ( unsigned i = 1; i != 0; i++ ) ; } int main() { std::clock_t start; std::clock_t end; std::cout<<"Beginning timer..."<<std::endl; start = std::clock(); long_running_operation(); end = std::clock(); std::cout<<"The operation took " << ( double ( end ) - start ) / CLOCKS_PER_SEC <<" seconds\n"; }
![]() |
Similar Threads
- Getting time from system clock in nanoseconds (C++)
- system clock/date language (Visual Basic 4 / 5 / 6)
- System clock lose about 4mins per hour!!! (Windows NT / 2000 / XP)
- Mandrake guest in VMware - System clock frozen... (*nix Software)
Other Threads in the C++ Forum
- Previous Thread: Quick Question! Post/pre Inc!
- Next Thread: Beginner C++ Prime Function Problem
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






