zlib使用与性能测试
作者:网络转载 发布时间:[ 2014/1/17 15:33:04 ] 推荐标签:zlib 性能测试
3.性能测试
针对1M数据分别调用compress压缩和uncompress解压缩,循环10次。
代码如下:
#include <stdio.h>
#include <time.h>
#include "zlib.h"
const int MAX_BUFFER_SIZE = 1024*1024*4;
unsigned char DATA_BUFFER[MAX_BUFFER_SIZE];
void testCompress()
{
const char * file = "/tmp/e2.txt.backup";
FILE *f1 = fopen(file,"r");
if(f1)
{
fseek(f1,0,2);
int len = ftell(f1);
fseek(f1,0,0);
char * data = new char[len];
fread(data,1,len,f1);
fclose(f1);
//uLong dst_len = MAX_BUFFER_SIZE;
//Bytef * dst = (Bytef*)DATA_BUFFER;
clock_t start = clock();
for(int i=0; i<10; i++)
{
uLong dst_len = MAX_BUFFER_SIZE;
Bytef * dst = (Bytef*)DATA_BUFFER;
compress(dst,&dst_len,(Bytef *)data,(uLong)len);
}
clock_t end = clock();
printf("time used(ms):%.2f
",1000.0*(end-start)/CLOCKS_PER_SEC);
delete [] data;
}
}
void testunCompress()
{
const char * file = "/tmp/2.gz";
FILE *f1 = fopen(file,"r");
if(f1)
{
fseek(f1,0,2);
int len = ftell(f1);
fseek(f1,0,0);
char * data = new char[len];
fread(data,1,len,f1);
fclose(f1);
//uLong dst_len = MAX_BUFFER_SIZE;
//Bytef * dst = (Bytef*)DATA_BUFFER;
clock_t start = clock();
for(int i=0; i<10; i++)
{
uLong dst_len = MAX_BUFFER_SIZE;
Bytef * dst = (Bytef*)DATA_BUFFER;
uncompress(dst,&dst_len,(Bytef *)data,(uLong)len);
}
clock_t end = clock();
printf("time used(ms):%.2f
",1000.0*(end-start)/CLOCKS_PER_SEC);
delete [] data;
}
}
int main(int argc, char **argv)
{
testCompress();
testunCompress();
return 0;
}
测试结果:
time used(ms):470.00
time used(ms):40.00
4.总结
zlib压缩1M数据耗时47ms左右,解压缩4ms左右。解压非常快。
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11