Skip to content

Instantly share code, notes, and snippets.

@skariel
Created November 11, 2013 09:07
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 skariel/7410160 to your computer and use it in GitHub Desktop.
Save skariel/7410160 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
double* func_cpp(double a, double inc, double b) {
double* buff;
for (auto i=0; i<1000; i++) {
int len= (int)((b-a)/inc);
buff = new double[len];
double* bi= buff;
for (auto v=a; v<b; v+=inc) {
*bi = v;
bi++;
}
delete[] buff;
}
return buff;
}
const double N=3;
const double ITER=5;
int main( )
{
clock_t min_dt;
auto set= false;
for (auto n=0; n<N; n++) {
auto ti= clock();
for (auto iter=0; iter<ITER; iter++)
func_cpp(0,.1,10000);
auto tf= clock();
auto dt= tf-ti;
if ((!set)||(dt < min_dt)) {
min_dt = dt;
set= true;
}
}
cout << "ms : " << min_dt/ITER/CLOCKS_PER_SEC*1000.0 << endl;
std::string name;
std::getline (std::cin,name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment