]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /********************************************************************** |
2 | Copyright(c) 2011-2016 Intel Corporation All rights reserved. | |
3 | ||
4 | Redistribution and use in source and binary forms, with or without | |
5 | modification, are permitted provided that the following conditions | |
6 | are met: | |
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 | |
12 | distribution. | |
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. | |
16 | ||
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 | **********************************************************************/ | |
29 | ||
30 | #include <stdio.h> | |
31 | #include <stdlib.h> | |
32 | #include <assert.h> | |
33 | #include "igzip_lib.h" | |
34 | #include "test.h" | |
35 | ||
36 | #define BUF_SIZE 1024 | |
37 | #define MIN_TEST_LOOPS 10 | |
38 | #ifndef RUN_MEM_SIZE | |
39 | # define RUN_MEM_SIZE 5000000000 | |
40 | #endif | |
41 | ||
42 | struct isal_zstream stream; | |
43 | ||
44 | int get_filesize(FILE * f) | |
45 | { | |
46 | int curr, end; | |
47 | ||
48 | curr = ftell(f); /* Save current position */ | |
49 | fseek(f, 0L, SEEK_END); | |
50 | end = ftell(f); | |
51 | fseek(f, curr, SEEK_SET); /* Restore position */ | |
52 | return end; | |
53 | } | |
54 | ||
55 | int main(int argc, char *argv[]) | |
56 | { | |
57 | FILE *in, *out = NULL; | |
58 | unsigned char *inbuf, *outbuf; | |
59 | int i, infile_size, iterations, outbuf_size; | |
60 | ||
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"); | |
65 | exit(0); | |
66 | } | |
67 | in = fopen(argv[1], "rb"); | |
68 | if (!in) { | |
69 | fprintf(stderr, "Can't open %s for reading\n", argv[1]); | |
70 | exit(0); | |
71 | } | |
72 | if (argc > 2) { | |
73 | out = fopen(argv[2], "wb"); | |
74 | if (!out) { | |
75 | fprintf(stderr, "Can't open %s for writing\n", argv[2]); | |
76 | exit(0); | |
77 | } | |
78 | printf("outfile=%s\n", argv[2]); | |
79 | } | |
80 | printf("Window Size: %d K\n", HIST_SIZE); | |
81 | printf("igzip_file_perf: \n"); | |
82 | fflush(0); | |
83 | /* Allocate space for entire input file and output | |
84 | * (assuming some possible expansion on output size) | |
85 | */ | |
86 | infile_size = get_filesize(in); | |
87 | ||
88 | if (infile_size != 0) { | |
89 | outbuf_size = infile_size * 1.07; | |
90 | iterations = RUN_MEM_SIZE / infile_size; | |
91 | } else { | |
92 | outbuf_size = BUF_SIZE; | |
93 | iterations = MIN_TEST_LOOPS; | |
94 | } | |
95 | if (iterations < MIN_TEST_LOOPS) | |
96 | iterations = MIN_TEST_LOOPS; | |
97 | ||
98 | inbuf = malloc(infile_size); | |
99 | if (inbuf == NULL) { | |
100 | fprintf(stderr, "Can't allocate input buffer memory\n"); | |
101 | exit(0); | |
102 | } | |
103 | outbuf = malloc(outbuf_size); | |
104 | if (outbuf == NULL) { | |
105 | fprintf(stderr, "Can't allocate output buffer memory\n"); | |
106 | exit(0); | |
107 | } | |
108 | ||
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"); | |
114 | exit(0); | |
115 | } | |
116 | ||
117 | struct perf start, stop; | |
118 | perf_start(&start); | |
119 | ||
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) | |
130 | break; | |
131 | } | |
132 | perf_stop(&stop); | |
133 | ||
134 | if (stream.avail_in != 0) { | |
135 | fprintf(stderr, "Could not compress all of inbuf\n"); | |
136 | exit(0); | |
137 | } | |
138 | ||
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); | |
141 | ||
142 | printf("igzip_file: "); | |
143 | perf_print(stop, start, (long long)infile_size * i); | |
144 | ||
145 | if (argc > 2 && out) { | |
146 | printf("writing %s\n", argv[2]); | |
147 | fwrite(outbuf, 1, stream.total_out, out); | |
148 | fclose(out); | |
149 | } | |
150 | ||
151 | fclose(in); | |
152 | printf("End of igzip_file_perf\n\n"); | |
153 | fflush(0); | |
154 | return 0; | |
155 | } |