]>
git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/igzip/igzip_inflate_perf.c
1 /**********************************************************************
2 Copyright(c) 2011-2016 Intel Corporation All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********************************************************************/
33 #include "huff_codes.h"
34 #include "igzip_inflate_ref.h"
38 #define MIN_TEST_LOOPS 100
40 # define RUN_MEM_SIZE 1000000000
43 int get_filesize(FILE * f
)
47 curr
= ftell(f
); /* Save current position */
48 fseek(f
, 0L, SEEK_END
);
50 fseek(f
, curr
, SEEK_SET
); /* Restore position */
54 int main(int argc
, char *argv
[])
56 FILE *in
, *out
= NULL
;
57 unsigned char *inbuf
, *outbuf
, *tempbuf
;
58 int i
, infile_size
, iterations
, outbuf_size
, check
;
60 struct inflate_state state
;
62 if (argc
> 3 || argc
< 2) {
63 fprintf(stderr
, "Usage: igzip_inflate_file_perf infile\n"
64 "\t - Runs multiple iterations of igzip on a file to "
65 "get more accurate time results.\n");
68 in
= fopen(argv
[1], "rb");
70 fprintf(stderr
, "Can't open %s for reading\n", argv
[1]);
74 out
= fopen(argv
[2], "wb");
76 fprintf(stderr
, "Can't open %s for writing\n", argv
[2]);
79 printf("outfile=%s\n", argv
[2]);
81 printf("igzip_inflate_perf: \n");
83 /* Allocate space for entire input file and output
84 * (assuming some possible expansion on output size)
86 infile_size
= get_filesize(in
);
88 if (infile_size
!= 0) {
89 outbuf_size
= infile_size
;
90 iterations
= RUN_MEM_SIZE
/ infile_size
;
92 printf("Error: input file has 0 size\n");
95 if (iterations
< MIN_TEST_LOOPS
)
96 iterations
= MIN_TEST_LOOPS
;
98 tempbuf
= malloc(infile_size
);
99 if (tempbuf
== NULL
) {
100 fprintf(stderr
, "Can't allocate temp buffer memory\n");
103 inbuf_size
= compressBound(infile_size
);
104 inbuf
= malloc(inbuf_size
);
106 fprintf(stderr
, "Can't allocate input buffer memory\n");
109 outbuf
= malloc(infile_size
);
110 if (outbuf
== NULL
) {
111 fprintf(stderr
, "Can't allocate output buffer memory\n");
114 fread(tempbuf
, 1, infile_size
, in
);
115 i
= compress2(inbuf
, &inbuf_size
, tempbuf
, infile_size
, 9);
117 printf("Compression of input file failed\n");
120 printf("igzip_inflate_perf: %s %d iterations\n", argv
[1], iterations
);
121 /* Read complete input file into buffer */
123 struct perf start
, stop
;
126 for (i
= 0; i
< iterations
; i
++) {
127 igzip_inflate_init(&state
, inbuf
+ 2, inbuf_size
- 2, outbuf
, outbuf_size
);
129 check
= igzip_inflate(&state
);
131 printf("Error in decompression with error %d\n", check
);
137 printf(" file %s - in_size=%d out_size=%d iter=%d\n", argv
[1],
138 infile_size
, state
.out_buffer
.total_out
, i
);
140 printf("igzip_file: ");
141 perf_print(stop
, start
, (long long)infile_size
* i
);
143 printf("End of igzip_inflate_perf\n\n");