| CODE |
| //computer speed #include<iostream> #include<ctime> using namespace std; int main() { clock_t delay = 10* CLOCKS_PER_SEC; int i; clock_t start=clock(); for (i=0;clock()-start<delay;i++) { cout <<"...Testing...\n"; } cout <<"After 10 seconds, " << i << " loops were done\n"; system("pause"); return 0; } |
| CODE |
| //averager #include<iostream> using namespace std; int main() { int * numbers=new int; cout<<"********************\n"; cout << " Averager \n"; cout<<"********************\n\n"; cout<<"Please enter the number of numbers you wish to average\n"; cin >> *numbers; cin.clear(); double *sum=new double; double *a_number=new double; for(int i=0;i< *numbers;i++) { cout << "Please enter a number\n"; cin >> *a_number; cout<< "\n"; *sum += *a_number; } cout << "The sum is "<< *sum<<"\n"; cout << "and the average is " << *sum / *numbers <<"\n"; system("pause"); delete numbers; delete a_number; delete sum; return 0; } |
| CODE |
| //:main.cpp // run a certain amount of tests and average the speeds #include<iostream> #include<ctime> typedef unsigned int uint; typedef unsigned long ulong; int testNumber = 1; /** run a test for a certain amount of seconds * @param unsigned int seconds - number of seconds to run the test for (in seconds) * @return void */ uint runTest(unsigned int seconds); void badInput(); int main() { std::cout << "Computer Speed Tester" << std::endl; bool exit = false; do { std::cout << "Enter the number of times to test, 0 to exit: "; uint tests; std::cin >> tests; if ( !std::cin.good() ) { badInput(); continue; } if ( tests == 0 ) { exit = true; continue; } std::cout << "Enter the length of each test (in seconds): "; uint seconds; std::cin >> seconds; if ( !std::cin.good() ) { badInput(); continue; } uint results = 0; for ( int testLoop = 0; testLoop < tests; testLoop++ ) results += runTest(seconds); testNumber = 1; long average = results / tests; std::cout << "\nYour average amount of loops is: " << average << "\n\n" << std::endl; } while ( !exit ); return 0; } uint runTest(uint seconds) { std::cout << "\nRunning test # " << testNumber << ", please wait..." << std::endl; clock_t delay = seconds * CLOCKS_PER_SEC; clock_t start = clock(); ulong testLoop; for ( testLoop = 0; clock() - start < delay; testLoop++ ); std::cout << "Your computer ran " << testLoop << " loops in " << seconds << " seconds" << std::endl; testNumber++; return testLoop; } void badInput() { std::cin.clear(); std::cin.ignore(INT_MAX, '\n'); std::cout << "ERROR: Bad input, please try again." << std::endl; } |
| CODE |
| #include <windows.h> #include <iostream> union __lollercopter { __int64 i64; struct { unsigned i32a,i32b; }; }a; __int64 GetCurrentCycles() { asm("rdtsc"); asm("movl %%eax,%0":"=r"(a.i32a)); asm("movl %%edx,%0":"=r"(a.i32b)); return a.i64; } int main() { LARGE_INTEGER sysfreq, time; __int64 et, result; QueryPerformanceFrequency(&sysfreq); QueryPerformanceCounter(&time); et = sysfreq.QuadPart + time.QuadPart; __int64 start = GetCurrentCycles(); while(time.QuadPart < et) QueryPerformanceCounter(&time); result = GetCurrentCycles() - start; std::cout << "You can execute approximately " << result << " instructions per second"; return 0; } |
| CODE |
| //computer speed #include<iostream> #include<fstream> #include<ctime> using namespace std; int main() { clock_t delay = 10* CLOCKS_PER_SEC; int i; string yn; clock_t start=clock(); for (i=0;clock()-start<delay;i++) { cout <<"...Testing...\n"; } cout <<"\aAfter 10 seconds, " << i << " loops were done\n"; cout << "Record this? y/n _\b"; cin >> yn; if(yn=="y") { ofstream myFile; myFile.open("cpu_speed_test_results.txt",ios::app); myFile << "Last test results: " << i << " loops \n"; myFile.close(); if (!myFile) { cout << "Error in file process." << endl; system("pause"); } else { cout << "Write successful!" << endl; system("pause"); } } return 0; } |
| QUOTE |
| You can execute approximately 3192070008 instructions per second. |
| CODE |
| //computer speed #include<iostream> #include<fstream> #include<ctime> using namespace std; int main() { clock_t delay = 10* CLOCKS_PER_SEC; int i; string yn; char notes[100]; clock_t start=clock(); for (i=0;clock()-start<delay;i++) { cout <<"...Testing...\n"; } cout <<"\aAfter 10 seconds, " << i << " loops were done\n"; cout << "Record this? y/n _\b"; cin >> yn; if(yn=="y") { ofstream myFile; myFile.open("cpu_speed_test_results.txt",ios::app); myFile << "Last test results: " << i << " loops \n"; myFile.close(); if (!myFile) { cout << "Error in file process." << endl; system("pause"); } else { cout << "Write successful!" << endl; } cin.clear(); cout << "\nAdd Notes? y/n \n"; cin >> yn; if(yn=="y") { cout << "Enter Notes"; cin.clear(); cin.get(); cin.getline(notes,100); ofstream myFile; myFile.open("cpu_speed_test_results.txt",ios::app); myFile << " : Notes : " << notes << "\n"; myFile.close(); } } return 0; } |
| CODE |
//V2-computer speed with more options #include<iostream> #include<fstream> #include<ctime> int menu(); using namespace std; int choice; int main() { while (true) { choice=menu(); if (choice==1) { clock_t delay = 10* CLOCKS_PER_SEC; int i; string yn; char notes[100]; clock_t start=clock(); for (i=0;clock()-start<delay;i++) { cout <<"...Testing...\n"; } cout <<"\aAfter 10 seconds, " << i << " loops were done\n"; cout << "Record this? y/n _\b"; cin >> yn; if(yn=="y") { time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); ofstream myFile; myFile.open("cpu_speed_test_results.txt",ios::app); myFile << "Last test results on " << asctime (timeinfo) << " Loops: " << i << "\n"; myFile.close(); if (!myFile) { cout << "Error in file process." << endl; system("pause"); } else { cout << "Write successful!" << endl; } cin.clear(); cout << "\nAdd Notes? y/n \n"; cin >> yn; if(yn=="y") { cout << "Enter Notes\n"; cin.clear(); cin.get(); cin.getline(notes,100); ofstream myFile; myFile.open("cpu_speed_test_results.txt",ios::app); myFile << " : Notes : " << notes << "\n"; myFile.close(); if (!myFile) { cout << "Error in file process.\n" << endl; system("pause"); } else { cout << "Write successful!\n" << endl; system ("pause"); } } } }//if 1 end if(choice==2) { ifstream file("cpu_speed_test_results.txt"); cout << file.rdbuf(); system("pause"); } }//while end return 0; } int menu() { cout << "\n" << "---------------\n Enter Choice: \n 1)Run CPU speed test\n 2)Read Previous tests (NOT COMPLETE DO NOT RUN)\n 3)Exit\n---------------\n Choice:_\b"; cin >> choice; if(choice==3) { exit(0); } else return choice; } |
| QUOTE (Rmstn1580 @ Mar 9 2006, 08:22 PM) |
| Also, when you delete pointers, don't you need to set them to null (0)? |
| QUOTE (Neken @ Mar 16 2006, 02:20 AM) | ||
No. |
| CODE |
/* CPU Speed Test V 8 Compatability version-No Monitoring Monitoring is not so usefull, I've found it uses up too many resources on older systems to be usefull for computing. */ #include <iostream> #include <fstream> #include <ctime> using namespace std; int menu(); int main (int argc, char * const argv[]) { int choice; char yn; char notes[100]; register long speed; int delay; choice = menu(); while(choice>0) { if(choice==1) { cout << "\nEnter number of whole seconds for test\n"; cin >> delay; if(!cin) { exit(0); } cout << "\nTesting, please wait\n"; clock_t test = delay* CLOCKS_PER_SEC; clock_t start=clock(); while(clock()-start<test) { speed++; } speed/=delay*1000; cout << "Loops per millisecond: " << speed; time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); ofstream myFile; myFile.open("radar_gun.txt",ios::app); myFile << "\nLast test results on " << asctime (timeinfo) << " Test Length: " << delay << "\n Loops/ms: " << speed << "\n"; cout << "\nAdd notes? y/n \n"; cin >> yn; if(!cin) { myFile.close(); exit(0); } else { if(yn=='y') { cout << "\nEnter notes\n "; cin.get(); cin.clear(); cin.get(notes,100); myFile << "\n ~ Notes: " << notes << "\n"; } } myFile.close(); cin.get(); cin.clear(); } if(choice==2) { ifstream file("radar_gun.txt"); cout << file.rdbuf(); cin.get(); cin.get(); } choice = menu(); } return 0; } int menu() { int choice_menu; cout << "\n" << "~~~~~~~~~~~~~~~~~~~~\n" << "Welcome to Radar Gun V.2.0!\n" << " 0) Quit\n" << " 1) Test\n" << " 2) Read Previous results\n" << "~~~~~~~~~~~~~~~~~~~~\n"; cin >> choice_menu; return choice_menu; } |