-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (49 loc) · 2.36 KB
/
main.cpp
File metadata and controls
61 lines (49 loc) · 2.36 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
#include <cstddef>
#include <iostream>
#include <vector>
#include "Allocator.h"
#include "Benchmark.h"
#include "CAllocator.h"
#include "FreeListAllocator.h"
#include "LinearAllocator.h"
#include "PoolAllocator.h"
#include "StackAllocator.h"
int main()
{
const std::size_t A = static_cast<std::size_t>(1e9);
const std::size_t B = static_cast<std::size_t>(1e8);
const std::vector<std::size_t> ALLOCATION_SIZES{32, 64, 256, 512, 1024, 2048, 4096};
const std::vector<std::size_t> ALIGNMENTS{8, 8, 8, 8, 8, 8, 8};
Allocator *cAllocator = new CAllocator();
Allocator *linearAllocator = new LinearAllocator(A);
Allocator *stackAllocator = new StackAllocator(A);
Allocator *poolAllocator = new PoolAllocator(16777216, 4096);
Allocator *freeListAllocator = new FreeListAllocator(B, FreeListAllocator::PlacementPolicy::FIND_FIRST);
Benchmark benchmark(OPERATIONS);
std::cout << "C" << std::endl;
benchmark.MultipleAllocation(cAllocator, ALLOCATION_SIZES, ALIGNMENTS);
benchmark.MultipleFree(cAllocator, ALLOCATION_SIZES, ALIGNMENTS);
benchmark.RandomAllocation(cAllocator, ALLOCATION_SIZES, ALIGNMENTS);
benchmark.RandomFree(cAllocator, ALLOCATION_SIZES, ALIGNMENTS);
std::cout << "LINEAR" << std::endl;
benchmark.MultipleAllocation(linearAllocator, ALLOCATION_SIZES, ALIGNMENTS);
benchmark.RandomAllocation(linearAllocator, ALLOCATION_SIZES, ALIGNMENTS);
std::cout << "STACK" << std::endl;
benchmark.MultipleAllocation(stackAllocator, ALLOCATION_SIZES, ALIGNMENTS);
benchmark.MultipleFree(stackAllocator, ALLOCATION_SIZES, ALIGNMENTS);
benchmark.RandomAllocation(stackAllocator, ALLOCATION_SIZES, ALIGNMENTS);
benchmark.RandomFree(stackAllocator, ALLOCATION_SIZES, ALIGNMENTS);
std::cout << "POOL" << std::endl;
benchmark.SingleAllocation(poolAllocator, 4096, 8);
benchmark.SingleFree(poolAllocator, 4096, 8);
std::cout << "FREE LIST" << std::endl;
benchmark.MultipleAllocation(freeListAllocator, ALLOCATION_SIZES, ALIGNMENTS);
benchmark.MultipleFree(freeListAllocator, ALLOCATION_SIZES, ALIGNMENTS);
benchmark.RandomAllocation(freeListAllocator, ALLOCATION_SIZES, ALIGNMENTS);
benchmark.RandomFree(freeListAllocator, ALLOCATION_SIZES, ALIGNMENTS);
delete cAllocator;
delete linearAllocator;
delete stackAllocator;
delete poolAllocator;
return 1;
}