Skip to content

Commit aadb160

Browse files
committed
doc: add doc for benchmark result
1 parent fb8649b commit aadb160

File tree

3 files changed

+1703
-10
lines changed

3 files changed

+1703
-10
lines changed

README.md

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
该项目是`WW`系列中,作为学习用途的内存池库
44

5-
## 特点
5+
## 一、特点
66

77
+ 采用`tcmalloc`的三层缓存架构,提高内存的分配效率
88

99
+ C++11风格,代码易读性强
1010

11-
## 结构
11+
## 二、结构
1212

1313
采用三层缓存的结构,其中
1414

@@ -18,31 +18,32 @@
1818

1919
+ 线程缓存`ThreadCache`: 管理少量的小块内存,负责从中心缓存中获取小块内存,并提供给应用程序使用
2020

21-
### 页缓存`PageCahce`
21+
### 1. 页缓存`PageCahce`
2222

2323
页缓存以页为单位管理内存,在中心缓存申请内存时,页缓存挑选合适的页段,然后将其切片成小块页段提供给中心缓存
2424

2525
![page_cache](doc/img/page_cache.png)
2626

27-
### 中心缓存`CentralCache`
27+
### 2. 中心缓存`CentralCache`
2828

2929
中心缓存从页缓存中获取合适大小的页段,然后根据需要的内存块大小,切割为一定数量的内存块,挂载到一个内存块链表上,供线程缓存使用
3030

3131
![central_cache](doc/img/central_cache.png)
3232

33-
### 线程缓存`ThreadCache`
33+
### 3. 线程缓存`ThreadCache`
3434

3535
线程缓存从中心缓存中批量获取内存块,供应用程序申请使用
3636

3737
![thread_cache](doc/img/thread_cache.png)
3838

39-
## 使用
39+
## 三、使用
4040

41-
### 要求
41+
### 1. 要求
4242

43-
+ 环境:`Linux x86_64`
43+
+ 操作系统:64位`Linux``Windows`
44+
+ C++:`C++11`或更高版本
4445

45-
### 直接使用
46+
### 2. 直接使用
4647

4748
直接操作线程缓存实例,示例见[threadcache_test.cpp](test/src/threadcache_test.cpp)
4849

@@ -64,7 +65,7 @@ int main()
6465
}
6566
```
6667

67-
### 封装使用
68+
### 3. 封装使用
6869

6970
将内存池封装为分配器等,示例见[memory_test.cpp](test/src/memory_test.cpp)
7071

@@ -89,3 +90,25 @@ void deallocate(pointer ptr, size_type n)
8990
thread_cache.deallocate(ptr, n * sizeof(T));
9091
}
9192
```
93+
94+
## 四、性能
95+
96+
基准测试位于[memory_benchmark.cpp](benchmark/src/memory_benchmark.cpp)
97+
98+
运行环境:
99+
100+
+ 操作系统:`Ubuntu 22.04 LTS`
101+
+ CPU:`12th Gen Intel(R) Core(TM) i7-12700`
102+
+ 核心/线程:4 核心 / 4 线程
103+
+ 内存:8 GB
104+
+ 虚拟化:`VMware`
105+
106+
### 1. 运行结果参考
107+
108+
![memory_benchmark](doc/img/memory_benchmark.png)
109+
110+
### 2. `perf`火焰图参考
111+
112+
火焰图来自基准测试中的[analyze_benchmark.cpp](benchmark/src/analyze_benchmark.cpp)
113+
114+
![flamegraph](doc/img/flamegraph.svg)

0 commit comments

Comments
 (0)