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 **********************************************************************/
34 #include "igzip_lib.h"
38 #define MIN_TEST_LOOPS 100
40 # define RUN_MEM_SIZE 500000000
43 struct isal_zstream stream
;
45 int get_filesize(FILE * f
)
49 curr
= ftell(f
); /* Save current position */
50 fseek(f
, 0L, SEEK_END
);
52 fseek(f
, curr
, SEEK_SET
); /* Restore position */
56 int main(int argc
, char *argv
[])
58 FILE *in
, *out
= NULL
;
59 unsigned char *inbuf
, *outbuf
;
60 int i
, infile_size
, iterations
, outbuf_size
;
61 struct isal_huff_histogram histogram
;
62 struct isal_hufftables hufftables_custom
;
64 memset(&histogram
, 0, sizeof(histogram
));
66 if (argc
> 3 || argc
< 2) {
67 fprintf(stderr
, "Usage: igzip_file_perf infile [outfile]\n"
68 "\t - Runs multiple iterations of igzip on a file to "
69 "get more accurate time results.\n");
72 in
= fopen(argv
[1], "rb");
74 fprintf(stderr
, "Can't open %s for reading\n", argv
[1]);
78 out
= fopen(argv
[2], "wb");
80 fprintf(stderr
, "Can't open %s for writing\n", argv
[2]);
83 printf("outfile=%s\n", argv
[2]);
85 printf("Window Size: %d K\n", HIST_SIZE
);
86 printf("igzip_file_perf: \n");
88 /* Allocate space for entire input file and output
89 * (assuming some possible expansion on output size)
91 infile_size
= get_filesize(in
);
93 if (infile_size
!= 0) {
94 outbuf_size
= infile_size
* 2;
95 iterations
= RUN_MEM_SIZE
/ infile_size
;
97 outbuf_size
= BUF_SIZE
;
98 iterations
= MIN_TEST_LOOPS
;
100 if (iterations
< MIN_TEST_LOOPS
)
101 iterations
= MIN_TEST_LOOPS
;
103 inbuf
= malloc(infile_size
);
105 fprintf(stderr
, "Can't allocate input buffer memory\n");
108 outbuf
= malloc(outbuf_size
);
109 if (outbuf
== NULL
) {
110 fprintf(stderr
, "Can't allocate output buffer memory\n");
114 printf("igzip_file_perf: %s %d iterations\n", argv
[1], iterations
);
115 /* Read complete input file into buffer */
116 stream
.avail_in
= (uint32_t) fread(inbuf
, 1, infile_size
, in
);
117 if (stream
.avail_in
!= infile_size
) {
118 fprintf(stderr
, "Couldn't fit all of input file into buffer\n");
122 struct perf start
, stop
;
125 for (i
= 0; i
< iterations
; i
++) {
126 isal_deflate_init(&stream
);
127 stream
.end_of_stream
= 1; /* Do the entire file at once */
128 stream
.flush
= NO_FLUSH
;
129 stream
.next_in
= inbuf
;
130 stream
.avail_in
= infile_size
;
131 stream
.next_out
= outbuf
;
132 stream
.avail_out
= outbuf_size
;
133 isal_deflate(&stream
);
134 if (stream
.avail_in
!= 0)
139 if (stream
.avail_in
!= 0) {
140 fprintf(stderr
, "Could not compress all of inbuf\n");
144 printf(" file %s - in_size=%d out_size=%d iter=%d ratio_default=%3.1f%%", argv
[1],
145 infile_size
, stream
.total_out
, i
, 100.0 * stream
.total_out
/ infile_size
);
147 isal_update_histogram(inbuf
, infile_size
, &histogram
);
148 isal_create_hufftables(&hufftables_custom
, &histogram
);
150 isal_deflate_init(&stream
);
151 stream
.end_of_stream
= 1; /* Do the entire file at once */
152 stream
.flush
= NO_FLUSH
;
153 stream
.next_in
= inbuf
;
154 stream
.avail_in
= infile_size
;
155 stream
.next_out
= outbuf
;
156 stream
.avail_out
= outbuf_size
;
157 stream
.hufftables
= &hufftables_custom
;
158 isal_deflate(&stream
);
160 printf(" ratio_custom=%3.1f%%\n", 100.0 * stream
.total_out
/ infile_size
);
162 if (stream
.avail_in
!= 0) {
163 fprintf(stderr
, "Could not compress all of inbuf\n");
167 printf("igzip_file: ");
168 perf_print(stop
, start
, (long long)infile_size
* i
);
170 if (argc
> 2 && out
) {
171 printf("writing %s\n", argv
[2]);
172 fwrite(outbuf
, 1, stream
.total_out
, out
);
177 printf("End of igzip_file_perf\n\n");