]>
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 100 | |
38 | #ifndef RUN_MEM_SIZE | |
39 | # define RUN_MEM_SIZE 500000000 | |
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_sync_flush_file_perf infile [outfile]\n" | |
63 | "\t - Runs multiple iterations of igzip on a file to get more accurate time results.\n"); | |
64 | exit(0); | |
65 | } | |
66 | in = fopen(argv[1], "rb"); | |
67 | if (!in) { | |
68 | fprintf(stderr, "Can't open %s for reading\n", argv[1]); | |
69 | exit(0); | |
70 | } | |
71 | if (argc > 2) { | |
72 | out = fopen(argv[2], "wb"); | |
73 | if (!out) { | |
74 | fprintf(stderr, "Can't open %s for writing\n", argv[2]); | |
75 | exit(0); | |
76 | } | |
77 | printf("outfile=%s\n", argv[2]); | |
78 | } | |
79 | printf("Window Size: %d K\n", HIST_SIZE); | |
80 | printf("igzip_sync_flush_file_perf: \n"); | |
81 | fflush(0); | |
82 | /* Allocate space for entire input file and | |
83 | * output (assuming 1:1 max output size) | |
84 | */ | |
85 | infile_size = get_filesize(in); | |
86 | ||
87 | if (infile_size != 0) { | |
88 | outbuf_size = infile_size; | |
89 | iterations = RUN_MEM_SIZE / infile_size; | |
90 | } else { | |
91 | outbuf_size = BUF_SIZE; | |
92 | iterations = MIN_TEST_LOOPS; | |
93 | } | |
94 | if (iterations < MIN_TEST_LOOPS) | |
95 | iterations = MIN_TEST_LOOPS; | |
96 | ||
97 | inbuf = malloc(infile_size); | |
98 | if (inbuf == NULL) { | |
99 | fprintf(stderr, "Can't allocate input buffer memory\n"); | |
100 | exit(0); | |
101 | } | |
102 | outbuf = malloc(outbuf_size); | |
103 | if (outbuf == NULL) { | |
104 | fprintf(stderr, "Can't allocate output buffer memory\n"); | |
105 | exit(0); | |
106 | } | |
107 | ||
108 | printf("igzip_sync_flush_file_perf: %s %d iterations\n", argv[1], iterations); | |
109 | /* Read complete input file into buffer */ | |
110 | stream.avail_in = (uint32_t) fread(inbuf, 1, infile_size, in); | |
111 | if (stream.avail_in != infile_size) { | |
112 | fprintf(stderr, "Couldn't fit all of input file into buffer\n"); | |
113 | exit(0); | |
114 | } | |
115 | ||
116 | struct perf start, stop; | |
117 | perf_start(&start); | |
118 | ||
119 | for (i = 0; i < iterations; i++) { | |
120 | isal_deflate_init(&stream); | |
121 | stream.end_of_stream = 0; | |
122 | stream.flush = SYNC_FLUSH; | |
123 | stream.next_in = inbuf; | |
124 | stream.avail_in = infile_size / 2; | |
125 | stream.next_out = outbuf; | |
126 | stream.avail_out = outbuf_size / 2; | |
127 | isal_deflate(&stream); | |
128 | if (infile_size == 0) | |
129 | continue; | |
130 | stream.avail_in = infile_size - infile_size / 2; | |
131 | stream.end_of_stream = 1; | |
132 | stream.next_in = inbuf + stream.total_in; | |
133 | stream.flush = SYNC_FLUSH; | |
134 | stream.avail_out = infile_size - outbuf_size / 2; | |
135 | stream.next_out = outbuf + stream.total_out; | |
136 | isal_deflate(&stream); | |
137 | if (stream.avail_in != 0) | |
138 | break; | |
139 | } | |
140 | perf_stop(&stop); | |
141 | ||
142 | if (stream.avail_in != 0) { | |
143 | fprintf(stderr, "Could not compress all of inbuf\n"); | |
144 | exit(0); | |
145 | } | |
146 | ||
147 | printf(" file %s - in_size=%d out_size=%d iter=%d ratio=%3.1f%%\n", argv[1], | |
148 | infile_size, stream.total_out, i, 100.0 * stream.total_out / infile_size); | |
149 | ||
150 | printf("igzip_file: "); | |
151 | perf_print(stop, start, (long long)infile_size * i); | |
152 | ||
153 | if (argc > 2 && out) { | |
154 | printf("writing %s\n", argv[2]); | |
155 | fwrite(outbuf, 1, stream.total_out, out); | |
156 | fclose(out); | |
157 | } | |
158 | ||
159 | fclose(in); | |
160 | printf("End of igzip_sync_flush_file_perf\n\n"); | |
161 | fflush(0); | |
162 | return 0; | |
163 | } |