// main.cpp - Testing FindArray and AsmFindArray. // Alternate version, 11/26/06, uses the clock() function for // millisecond resolution. #include #include #include "findarr.h" using namespace std; int main() { // Fill an array with pseudorandom integers. const unsigned ARRAY_SIZE = 10000; const unsigned LOOP_SIZE = 1000000; long array[ARRAY_SIZE]; for(unsigned i = 0; i < ARRAY_SIZE; i++) array[i] = rand(); long searchVal; clock_t startTime, endTime; cout << "Enter value to find: "; cin >> searchVal; cout << "Please wait. This will take between 10 and 30 seconds...\n"; // Test the C++ function: //time( &startTime ); startTime = clock(); bool found = false; for( int n = 0; n < LOOP_SIZE; n++) found = FindArray( searchVal, array, ARRAY_SIZE ); //time( &endTime ); endTime = clock(); double duration = (double)(endTime - startTime) / CLOCKS_PER_SEC; cout << "Elapsed CPP time: " << duration << " seconds. Found = " << found << endl; // Test the Assembly language procedure: startTime = clock(); found = false; for( int n = 0; n < LOOP_SIZE; n++) found = AsmFindArray( searchVal, array, ARRAY_SIZE ); endTime = clock(); duration = (double)(endTime - startTime) / CLOCKS_PER_SEC; cout << "Elapsed ASM time: " << duration << " seconds. Found = " << found << endl; return 0; }