]>
git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/igzip/igzip_stateless_file_perf.c
d82615a7a418ac9a24a53e4d2405ae0c745288ee
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 "igzip_lib.h"
37 #define MIN_TEST_LOOPS 10
39 # define RUN_MEM_SIZE 5000000000
42 struct isal_zstream stream
;
44 int get_filesize(FILE * f
)
48 curr
= ftell(f
); /* Save current position */
49 fseek(f
, 0L, SEEK_END
);
51 fseek(f
, curr
, SEEK_SET
); /* Restore position */
55 int main(int argc
, char *argv
[])
57 FILE *in
, *out
= NULL
;
58 unsigned char *inbuf
, *outbuf
;
59 int i
, infile_size
, iterations
, outbuf_size
;
61 if (argc
> 3 || argc
< 2) {
62 fprintf(stderr
, "Usage: igzip_file_perf infile [outfile]\n"
63 "\t - Runs multiple iterations of igzip on a file to "
64 "get more accurate time results.\n");
67 in
= fopen(argv
[1], "rb");
69 fprintf(stderr
, "Can't open %s for reading\n", argv
[1]);
73 out
= fopen(argv
[2], "wb");
75 fprintf(stderr
, "Can't open %s for writing\n", argv
[2]);
78 printf("outfile=%s\n", argv
[2]);
80 printf("Window Size: %d K\n", HIST_SIZE
);
81 printf("igzip_file_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
* 1.07;
90 iterations
= RUN_MEM_SIZE
/ infile_size
;
92 outbuf_size
= BUF_SIZE
;
93 iterations
= MIN_TEST_LOOPS
;
95 if (iterations
< MIN_TEST_LOOPS
)
96 iterations
= MIN_TEST_LOOPS
;
98 inbuf
= malloc(infile_size
);
100 fprintf(stderr
, "Can't allocate input buffer memory\n");
103 outbuf
= malloc(outbuf_size
);
104 if (outbuf
== NULL
) {
105 fprintf(stderr
, "Can't allocate output buffer memory\n");
109 printf("igzip_file_perf: %s %d iterations\n", argv
[1], iterations
);
110 /* Read complete input file into buffer */
111 stream
.avail_in
= (uint32_t) fread(inbuf
, 1, infile_size
, in
);
112 if (stream
.avail_in
!= infile_size
) {
113 fprintf(stderr
, "Couldn't fit all of input file into buffer\n");
117 struct perf start
, stop
;
120 for (i
= 0; i
< iterations
; i
++) {
121 isal_deflate_init(&stream
);
122 stream
.end_of_stream
= 1; /* Do the entire file at once */
123 stream
.flush
= NO_FLUSH
;
124 stream
.next_in
= inbuf
;
125 stream
.avail_in
= infile_size
;
126 stream
.next_out
= outbuf
;
127 stream
.avail_out
= outbuf_size
;
128 isal_deflate_stateless(&stream
);
129 if (stream
.avail_in
!= 0)
134 if (stream
.avail_in
!= 0) {
135 fprintf(stderr
, "Could not compress all of inbuf\n");
139 printf(" file %s - in_size=%d out_size=%d iter=%d ratio=%3.1f%%\n", argv
[1],
140 infile_size
, stream
.total_out
, i
, 100.0 * stream
.total_out
/ infile_size
);
142 printf("igzip_file: ");
143 perf_print(stop
, start
, (long long)infile_size
* i
);
145 if (argc
> 2 && out
) {
146 printf("writing %s\n", argv
[2]);
147 fwrite(outbuf
, 1, stream
.total_out
, out
);
152 printf("End of igzip_file_perf\n\n");