-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtofevent_classic.cpp
61 lines (51 loc) · 1.46 KB
/
tofevent_classic.cpp
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
/* malloc example: string generator*/
#include <MantidKernel/CPUTimer.h>
#include <MantidKernel/Memory.h>
#include <MantidKernel/Timer.h>
#include <MantidTypes/Event/TofEvent.h>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <unistd.h>
#include <vector>
using Mantid::Kernel::CPUTimer;
using Mantid::Kernel::MemoryStats;
using Mantid::Kernel::Timer;
using Mantid::Types::Event::TofEvent;
using std::cout;
using std::string;
int main(int argc, char *argv[]) {
constexpr int sleeptime{2};
// this tops out at roughly 30GB
std::vector<std::size_t> VECTOR_LENGTH{100000, 1000000, 10000000, 100000000, 1000000000, 2000000000};
CPUTimer timer;
MemoryStats memory;
for (auto const length : VECTOR_LENGTH) {
std::cout << "VECTOR SIZE = " << length << "\n";
// reserve memory
auto *buffer = new std::vector<TofEvent>();
buffer->reserve(length);
memory.update();
cout << "Allocate: " << timer << "\n" << memory << std::endl;
sleep(sleeptime);
timer.reset();
// fill up the vector
for (std::size_t n = 0; n < length; n++)
buffer->emplace_back(0, 0);
memory.update();
cout << "Fill: " << timer << "\n" << memory << "\n";
sleep(sleeptime);
timer.reset();
// free memory
delete buffer;
memory.update();
cout << "Free: " << timer << "\n" << memory << std::endl;
timer.reset();
}
return 0;
}