Created
April 23, 2015 17:29
-
-
Save shivallan/6c7b7f5f57333359751b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <vector> | |
#include <algorithm> | |
#include <iostream> | |
#include <sys/time.h> | |
#include <cstdlib> | |
using namespace std; | |
int main() | |
{ | |
timeval t1, t2; | |
double elapsedTime; | |
std::vector<long> v(100000000); // vector for 100000000 elements | |
std::generate(v.begin(), v.end(), rand); // filling with random numbers | |
// start timer | |
gettimeofday(&t1, NULL); | |
std::reverse(v.begin(),v.end()); // REVERSE HERE | |
// stop timer | |
gettimeofday(&t2, NULL); | |
// compute and print the elapsed time in millisec | |
elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms | |
elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms | |
std::cout << "reverse -> " << elapsedTime << " ms.\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment