-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject_hog.cpp
64 lines (41 loc) · 1.46 KB
/
object_hog.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
62
63
64
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include "ivymike/time.h"
int main() {
std::vector<std::vector<char> > bufs;
bool alloc = true;
size_t size = 0;
size_t num_allocs = 0;
size_t last_allocs = 0;
const size_t low_size = 128 * 1024 * 1024;
const size_t high_size = size_t(low_size * 1.1);
ivy_mike::timer t1;
while( true ) {
if( t1.elapsed() > 5.0 ) {
std::cout << "alloc: " << size * 1.0e-6 << " MB " << num_allocs - last_allocs << "\n";
t1 = ivy_mike::timer();
last_allocs = num_allocs;
}
++num_allocs;
if( alloc ) {
const size_t as = (rand() % 1024) * 16;
bufs.emplace_back( as );
std::fill( bufs.back().begin(), bufs.back().end(), char(size) );
size += as;
if( size > high_size ) {
alloc = false;
}
} else {
const size_t re = rand() % bufs.size();
std::vector<std::vector<char> >::iterator it = bufs.begin() + re;
assert( it < bufs.end() );
size -= it->size();
bufs.erase( it );
if( size < low_size ) {
alloc = true;
}
}
}
}