-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_alloc.cc
50 lines (46 loc) · 1.13 KB
/
test_alloc.cc
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
#include <gtest/gtest.h>
#include "alloc.h"
#include <iostream>
#include <stdlib.h>
#include <random>
TEST(alloc,construct){
msgskip::misc::single_thread_arena<std::allocator<char> > a;
}
TEST(alloc,and_use){
msgskip::misc::single_thread_arena<std::allocator<char> > a;
char* ptr = a.allocate(523);
#ifndef NDEBUG
std::cout << "memory usage:" << a.memory_usage() << std::endl;
#endif
for(int i=0;i<523;i++){
ptr[i] = (i*31)&255;
}
}
TEST(alloc,many){
msgskip::misc::single_thread_arena<std::allocator<char> > a;
for(int j=0;j<5048;++j){
char* ptr = a.allocate(523);
for(int i=0;i<523;i++){
ptr[i] = (i*31)&255;
}
#ifndef NDEBUG
std::cout << "memory usage:" << a.memory_usage() << std::endl;
#endif
}
}
TEST(alloc,random){
msgskip::misc::single_thread_arena<std::allocator<char> > a;
for(int j=0;j<1024;++j){
const size_t rand_size = rand() % 8196;
#ifndef NDEBUG
std::cout << "begin allocate:" << rand_size << std::endl;
#endif
char* ptr = a.allocate(rand_size);
for(size_t i=0;i<rand_size;i++){
ptr[i] = (i*31)&255;
}
#ifndef NDEBUG
std::cout << "memory usage:" << a.memory_usage() << std::endl;
#endif
}
}