Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions timecheck.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <algorithm>
#include <chrono>
#include <iostream>
#include<vector>
using namespace std;
using namespace std::chrono;
int main()
{

vector<int> values(10000);

// Generate Random values
auto f = []() -> int { return rand() % 10000; };

// Fill up the vector
generate(values.begin(), values.end(), f);

// Get starting timepoint
auto start = high_resolution_clock::now();

// Call the function, here sort()
sort(values.begin(), values.end());

// Get ending timepoint
auto stop = high_resolution_clock::now();

// Get duration. Substart timepoints to
// get durarion. To cast it to proper unit
// use duration cast method
auto duration = duration_cast<microseconds>(stop - start);

cout << "Time taken by function: "
<< duration.count() << " microseconds" << endl;

return 0;
}