提交 96344162 编写于 作者: R russelltao

增加java程序

上级 609d63ba
### 编译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
......
#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.
先完成此消息的编辑!
想要评论请 注册