Timer - end += clock() - start; } //Stop the count if...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
UAH CPE 212 Timer #include <climits> #include <ctime> #include <iostream> using namespace std; int main() { const int Extra=1000; //Machine is too fast, add extra work int MyInts[USHRT_MAX]; //Static array of ints bool DisplayIt=false; //Show filled array? char temp; //A dummy input to keep from exiting clock_t start=0; //Start time in processor ticks clock_t end=0; //Stop time in processor ticks //Start the count for (unsigned j=0; j<Extra; j++) //Should time loops separately { start= clock(); for (unsigned i=0; i<USHRT_MAX; i++) MyInts[i] = i;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: end += clock() - start; } //Stop the count if (DisplayIt) for (unsigned i=0; i&lt;USHRT_MAX; i++) cout&lt;&lt;MyInts[i]&lt;&lt;endl; double ElapsedTicks = (double)(end); double ElapsedTime = (double)(ElapsedTicks/((double)CLOCKS_PER_SEC*Extra) ); double InTime = ElapsedTime/(double)USHRT_MAX; cout&lt;&lt;&quot;Total Time Elapsed: &quot;&lt;&lt;ElapsedTime&lt;&lt;endl; cout&lt;&lt;&quot;Average Insert Time: &quot;&lt;&lt;InTime&lt;&lt;endl; cin&gt;&gt;temp; //Forces a pause until a character is entered return 0; }...
View Full Document

Ask a homework question - tutors are online