Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
陶辉
geektime_distrib_perf
提交
96344162
G
geektime_distrib_perf
项目概览
陶辉
/
geektime_distrib_perf
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
geektime_distrib_perf
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
96344162
编写于
11月 25, 2019
作者:
R
russelltao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加java程序
上级
609d63ba
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
15 deletion
+21
-15
2-memory/benchmark/README.md
2-memory/benchmark/README.md
+20
-12
2-memory/benchmark/benchmark.cpp
2-memory/benchmark/benchmark.cpp
+1
-3
未找到文件。
2-memory/benchmark/README.md
浏览文件 @
96344162
### 编译tcmalloc库
### 1 在栈中分配内存速度更快
heap_stack.java验证在栈中分配内存比堆中更快
#### 1.1 编译
javac heap_stack.java
#### 1.2 运行
java heap_stack
### 2 编译tcmalloc库
使用TCMalloc库前,需要下载编译它
#### 预安装库
autoconf、automake、libtool
CentOS下安装:yum install autoconf automake libtool
Ubuntu下安装:apt-get install autoconf、automake、libtool
#### 下载gperftool
####
2.1
下载gperftool
https://github.com/gperftools/gperftools.git
#### 生成configure文件
####
2.2
生成configure文件
./autogen.sh
#### 生成Makefile文件
####
2.3
生成Makefile文件
./configure
*配置选项通过--help查询*
#### 编译
####
2.4
编译
make
#### 安装
####
2.5
安装
make install
### benchmark性能测试
#### 编译benchmark文件
###
3
benchmark性能测试
对比测试tcmalloc与ptmalloc2的性能
####
3.1
编译benchmark文件
g++ benchmark.cpp -o benchmark -lpthread
#### benchmark命令行选项
####
3.2
benchmark命令行选项
1.
-s: 分配内存块大小,单位字节
2.
-t: 线程数
3.
-n: 每个线程循环分配内存的次数
#### 基于ptmalloc2测试
#### 3.3 基于ptmalloc2测试
##### 单线程分配256KB
export LD_PRELOAD=""; ./benchmark -s 262144 -t 1
##### 2线程分配256KB
...
...
@@ -39,7 +47,7 @@ export LD_PRELOAD=""; ./benchmark -s 262145 -t 1
##### 10线程分配256KB+1字节
export LD_PRELOAD=""; ./benchmark -s 262145 -t 10
#### 基于TcMalloc测试
####
3.4
基于TcMalloc测试
*根据configure生成的libtcmalloc.so文件的位置填写LD_PRELOAD*
##### 单线程分配256KB
export LD_PRELOAD="/lib64/libtcmalloc.so"; ./benchmark -s 262144 -t 1
...
...
2-memory/benchmark/benchmark.cpp
浏览文件 @
96344162
#include "stdio.h"
#include <stdlib.h>
#include <sys/time.h>
#include <iostream>
#include <unistd.h>
#include <pthread.h>
using
namespace
std
;
int
TESTN
=
128
*
1024
*
1024
;
int
size
=
64
;
...
...
@@ -61,7 +59,7 @@ int main(int argc, char** argv) {
int
ret
=
pthread_create
(
&
id
[
i
],
NULL
,
loopalloc
,
&
timecost
[
i
]);
if
(
ret
!=
0
){
cout
<<
"Create pthread error!
\n
"
;
printf
(
"Create pthread error!
\n
"
)
;
exit
(
1
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录