????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?????????????