-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread_time.cpp
More file actions
33 lines (27 loc) · 763 Bytes
/
thread_time.cpp
File metadata and controls
33 lines (27 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <chrono>
#include <vector>
#include <thread>
#include <utility>
#include <tuple>
using namespace std;
void loop(){
}
int main(int argc, char * argv[]){
if (argc == 1){
cout << "Usage is: " << argv[0] << "nt " << endl;
return (-1);
}
int nt = atoi (argv[1]);
vector <thread> tvec;
auto start = std::chrono::system_clock::now();
for (int i=0; i< nt; i++)
tvec.push_back(thread(loop));
for (int i=0; i< nt; i++)
tvec[i].join();
auto end = std::chrono::system_clock::now();
chrono::duration<double> time = end-start;
std::cout << "Time to setup " << nt << "threads = " << time.count() << " s\n";
std::cout << "Avg time to setup one thread " << ((double)time.count())/((double)nt) << " s\n";
return 0;
}