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 8
40 # define RUN_MEM_SIZE 2000000000
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 void print_histogram(struct isal_huff_histogram
*histogram
)
57 printf("Lit Len histogram");
58 for (i
= 0; i
< ISAL_DEF_LIT_LEN_SYMBOLS
; i
++) {
63 printf("%4lu", histogram
->lit_len_histogram
[i
]);
67 printf("Dist histogram");
68 for (i
= 0; i
< ISAL_DEF_DIST_SYMBOLS
; i
++) {
73 printf("%4lu", histogram
->dist_histogram
[i
]);
78 int main(int argc
, char *argv
[])
81 unsigned char *inbuf
, *outbuf
;
82 int i
, infile_size
, outbuf_size
, iterations
, avail_in
;
83 struct isal_huff_histogram histogram1
, histogram2
;
85 memset(&histogram1
, 0, sizeof(histogram1
));
86 memset(&histogram2
, 0, sizeof(histogram2
));
88 if (argc
> 3 || argc
< 2) {
89 fprintf(stderr
, "Usage: igzip_file_perf infile [outfile]\n"
90 "\t - Runs multiple iterations of igzip on a file to "
91 "get more accurate time results.\n");
94 in
= fopen(argv
[1], "rb");
96 fprintf(stderr
, "Can't open %s for reading\n", argv
[1]);
100 /* Allocate space for entire input file and output
101 * (assuming some possible expansion on output size)
103 infile_size
= get_filesize(in
);
104 outbuf_size
= 2 * infile_size
;
106 if (infile_size
!= 0)
107 iterations
= RUN_MEM_SIZE
/ infile_size
;
109 iterations
= MIN_TEST_LOOPS
;
111 if (iterations
< MIN_TEST_LOOPS
)
112 iterations
= MIN_TEST_LOOPS
;
114 inbuf
= malloc(infile_size
);
115 outbuf
= malloc(outbuf_size
);
117 fprintf(stderr
, "Can't allocate input buffer memory\n");
121 if (outbuf
== NULL
) {
122 fprintf(stderr
, "Can't allocate output buffer memory\n");
126 avail_in
= fread(inbuf
, 1, infile_size
, in
);
127 if (avail_in
!= infile_size
) {
128 fprintf(stderr
, "Couldn't fit all of input file into buffer\n");
132 struct perf start
, stop
;
135 for (i
= 0; i
< iterations
; i
++)
136 isal_update_histogram(inbuf
, infile_size
, &histogram1
);
139 printf(" file %s - in_size=%d iter=%d\n", argv
[1], infile_size
, i
);
140 printf("igzip_file: ");
141 perf_print(stop
, start
, (long long)infile_size
* i
);