Created
November 11, 2013 09:07
-
-
Save skariel/7410160 to your computer and use it in GitHub Desktop.
to compare with https://gist.github.com/kmsquire/7403647
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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