-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbench.c
66 lines (51 loc) · 1.09 KB
/
bench.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#if USE_LZF
#include "lzf.h"
#else
#include "lzfx.h"
#endif
typedef unsigned char u8;
#define BLOCKSIZE (1024*1024)
#define NITER 100
int main(int argc, char* argv[]){
int ifd, rc, i;
u8* data = NULL;
u8* obuf = NULL;
unsigned int olen;
unsigned int count=0;
ifd = open(argv[1], O_RDONLY);
if(ifd<0){
return 1;
}
do {
data = realloc(data, count+BLOCKSIZE);
rc = read(ifd, data, BLOCKSIZE);
if(rc<0){
return -1;
}
count += rc;
} while(rc > 0);
fprintf(stderr, "read %u bytes\n", count);
olen = count*2;
obuf = (u8*)malloc(olen);
for(i=0;i<NITER;i++){
#if USE_LZF
rc = lzf_compress(data, count, obuf, olen);
if(rc==0){
fprintf(stderr, "fail\n");
return 1;
}
#else
rc = lzfx_compress(data, count, obuf, &olen);
if(rc<0){
fprintf(stderr, "fail\n");
return -rc;
}
#endif
olen = count*2;
}
return 0;
}