Skip to content

Instantly share code, notes, and snippets.

@kireal
Forked from shivallan/Reverse
Last active August 29, 2015 14:19
Show Gist options
  • Save kireal/ef14521cc5fbb0516ece to your computer and use it in GitHub Desktop.
Save kireal/ef14521cc5fbb0516ece to your computer and use it in GitHub Desktop.
#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