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