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 **********************************************************************/
30 #define _FILE_OFFSET_BITS 64
35 #include "igzip_lib.h"
39 #define MIN_TEST_LOOPS 8
41 # define RUN_MEM_SIZE 2000000000
44 void print_histogram(struct isal_huff_histogram
*histogram
)
47 printf("Lit Len histogram");
48 for (i
= 0; i
< ISAL_DEF_LIT_LEN_SYMBOLS
; i
++) {
53 printf("%4lu", histogram
->lit_len_histogram
[i
]);
57 printf("Dist histogram");
58 for (i
= 0; i
< ISAL_DEF_DIST_SYMBOLS
; i
++) {
63 printf("%4lu", histogram
->dist_histogram
[i
]);
68 int main(int argc
, char *argv
[])
71 unsigned char *inbuf
, *outbuf
;
72 int i
, iterations
, avail_in
;
73 uint64_t infile_size
, outbuf_size
;
74 struct isal_huff_histogram histogram1
, histogram2
;
76 memset(&histogram1
, 0, sizeof(histogram1
));
77 memset(&histogram2
, 0, sizeof(histogram2
));
79 if (argc
> 3 || argc
< 2) {
80 fprintf(stderr
, "Usage: igzip_file_perf infile [outfile]\n"
81 "\t - Runs multiple iterations of igzip on a file to "
82 "get more accurate time results.\n");
85 in
= fopen(argv
[1], "rb");
87 fprintf(stderr
, "Can't open %s for reading\n", argv
[1]);
91 /* Allocate space for entire input file and output
92 * (assuming some possible expansion on output size)
94 infile_size
= get_filesize(in
);
95 outbuf_size
= 2 * infile_size
;
98 iterations
= RUN_MEM_SIZE
/ infile_size
;
100 iterations
= MIN_TEST_LOOPS
;
102 if (iterations
< MIN_TEST_LOOPS
)
103 iterations
= MIN_TEST_LOOPS
;
105 inbuf
= malloc(infile_size
);
106 outbuf
= malloc(outbuf_size
);
108 fprintf(stderr
, "Can't allocate input buffer memory\n");
112 if (outbuf
== NULL
) {
113 fprintf(stderr
, "Can't allocate output buffer memory\n");
117 avail_in
= fread(inbuf
, 1, infile_size
, in
);
118 if (avail_in
!= infile_size
) {
119 fprintf(stderr
, "Couldn't fit all of input file into buffer\n");
123 struct perf start
, stop
;
126 for (i
= 0; i
< iterations
; i
++)
127 isal_update_histogram(inbuf
, infile_size
, &histogram1
);
130 printf(" file %s - in_size=%lu iter=%d\n", argv
[1], infile_size
, i
);
131 printf("igzip_file: ");
132 perf_print(stop
, start
, (long long)infile_size
* i
);