-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLinuxSingle.cpp
More file actions
65 lines (46 loc) · 1.45 KB
/
Copy pathLinuxSingle.cpp
File metadata and controls
65 lines (46 loc) · 1.45 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Single Threaded Implementation
------------------------------
Generates uniformly distributed random integers in the range
1-1000, inclusive.
*/
//https://linuxhint.com/use-linux-chrt-command/
//https://stackoverflow.com/questions/41150975/how-to-display-list-of-running-processes-python
//ps -eLf | grep ./dum
//Linux magix-83 4.19.0-22-amd64 #1 SMP Debian 4.19.260-1 (2022-09-29) x86_64 GNU/Linux
//chrt --help
//https://www.tutorialspoint.com/how-to-create-a-high-resolution-timer-with-cplusplus-and-linux
#include <iostream>
#include <thread>
#include <vector>
#include <random>
#include <chrono>
using Clock = std::chrono::high_resolution_clock;
namespace Vars
{
const unsigned int N = std::thread::hardware_concurrency(); //number of threads on device
const unsigned int NumPerThread = 5e6; //number of random numbers to generate per thread
std::vector<int> RandNums(NumPerThread*N);
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(1, 1000);
int sz = 0;
}
using namespace Vars;
void AddN()
{
for (unsigned int i=0; i<NumPerThread*N; i++)
{
RandNums[i] = dis(gen);
++sz;
}
}
int main()
{
auto start_time = Clock::now();
AddN();
auto end_time = Clock::now();
std::cout << "Time difference = "
<< std::chrono::duration<double, std::nano>(end_time - start_time).count() << " nanoseconds\n";
std::cout << "size = " << sz << '\n';
}