Skip to content

Instantly share code, notes, and snippets.

@KSXGitHub
Created June 10, 2015 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KSXGitHub/57dc9536c98dbb444443 to your computer and use it in GitHub Desktop.
Save KSXGitHub/57dc9536c98dbb444443 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <ctime>
#include <chrono>
using std::cout;
using std::endl;
using std::chrono::time_point;
using std::chrono::system_clock;
using std::chrono::duration;
int main(){
int pause;
int time;
bool running = true;
do {
double numberOfRuns = 0;
cout << "Hello Welcome to the function tester." << endl;
cout << "How many seconds would you like to test for? ( 0 to quit )" << endl;
std::cin >> time;
//Exit Program Condition
if(time)
{
time_point<system_clock> start, end;
start = system_clock::now();
duration<double> elapsed_seconds;
while(elapsed_seconds.count() < time){
//INSERT FUNCTION YOU WANT TO TIME HERE
//int i = 0;
//i = 1 + 1; ???
//do you mean int i = 0; ++i; ??
int i = 2;
//INSERT FUNCTION YOU WANT TO TIME UP THERE
++numberOfRuns;
//Update timing
end = system_clock::now();
elapsed_seconds = end - start;
}
//Output Data
cout << "elapsed time is : " << elapsed_seconds.count() << endl;
cout << "Number of runs is : " << numberOfRuns << endl << endl;
cout << "Average runs per second is : " << numberOfRuns / elapsed_seconds.count() << endl;
cout << "Average runs per frame at 60 FPS is : " << (numberOfRuns / elapsed_seconds.count()) / 60 << endl;
cout << "One execution takes : " << elapsed_seconds.count() / numberOfRuns << "seconds." << endl << endl;
cout << "Press 1 to continue" << endl;
std::cin >> pause;
//Clear Screen
for (int i = 0; i != 50; ++i){
cout << endl;
}
//or system('cls') in windows or system('clear') in linux
} else {
running = false
};
} while(running)
return 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment