Rizin
unix-like reverse engineering framework and cli tools
compress_functions.c File Reference
#include "lz4.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include <time.h>
#include <locale.h>

Go to the source code of this file.

Macros

#define _XOPEN_SOURCE   500
 
#define _POSIX_C_SOURCE   199309L
 
#define LZ4_DISABLE_DEPRECATE_WARNINGS   /* LZ4_decompress_fast */
 
#define BILLION   1000000000L
 
#define ID__LZ4_COMPRESS_DEFAULT   1
 
#define ID__LZ4_COMPRESS_FAST   2
 
#define ID__LZ4_COMPRESS_FAST_EXTSTATE   3
 
#define ID__LZ4_COMPRESS_GENERIC   4
 
#define ID__LZ4_DECOMPRESS_SAFE   5
 
#define ID__LZ4_DECOMPRESS_FAST   6
 

Functions

void run_screaming (const char *message, const int code)
 
void usage (const char *message)
 
uint64_t bench (const char *known_good_dst, const int function_id, const int iterations, const char *src, char *dst, const size_t src_size, const size_t max_dst_size, const size_t comp_size)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   199309L

Definition at line 60 of file compress_functions.c.

◆ _XOPEN_SOURCE

#define _XOPEN_SOURCE   500

Definition at line 58 of file compress_functions.c.

◆ BILLION

#define BILLION   1000000000L

Definition at line 74 of file compress_functions.c.

◆ ID__LZ4_COMPRESS_DEFAULT

#define ID__LZ4_COMPRESS_DEFAULT   1

Definition at line 77 of file compress_functions.c.

◆ ID__LZ4_COMPRESS_FAST

#define ID__LZ4_COMPRESS_FAST   2

Definition at line 78 of file compress_functions.c.

◆ ID__LZ4_COMPRESS_FAST_EXTSTATE

#define ID__LZ4_COMPRESS_FAST_EXTSTATE   3

Definition at line 79 of file compress_functions.c.

◆ ID__LZ4_COMPRESS_GENERIC

#define ID__LZ4_COMPRESS_GENERIC   4

Definition at line 80 of file compress_functions.c.

◆ ID__LZ4_DECOMPRESS_FAST

#define ID__LZ4_DECOMPRESS_FAST   6

Definition at line 82 of file compress_functions.c.

◆ ID__LZ4_DECOMPRESS_SAFE

#define ID__LZ4_DECOMPRESS_SAFE   5

Definition at line 81 of file compress_functions.c.

◆ LZ4_DISABLE_DEPRECATE_WARNINGS

#define LZ4_DISABLE_DEPRECATE_WARNINGS   /* LZ4_decompress_fast */

Definition at line 63 of file compress_functions.c.

Function Documentation

◆ bench()

uint64_t bench ( const char *  known_good_dst,
const int  function_id,
const int  iterations,
const char *  src,
char *  dst,
const size_t  src_size,
const size_t  max_dst_size,
const size_t  comp_size 
)

Definition at line 109 of file compress_functions.c.

118  {
119  uint64_t time_taken = 0;
120  int rv = 0;
121  const int warm_up = 5000;
122  struct timespec start, end;
123  const int acceleration = 1;
125 
126  // Select the right function to perform the benchmark on. We perform 5000 initial loops to warm the cache and ensure that dst
127  // remains matching to known_good_dst between successive calls.
128  switch(function_id) {
130  printf("Starting benchmark for function: LZ4_compress_default()\n");
131  for(int junk=0; junk<warm_up; junk++)
132  rv = LZ4_compress_default(src, dst, src_size, max_dst_size);
133  if (rv < 1)
134  run_screaming("Couldn't run LZ4_compress_default()... error code received is in exit code.", rv);
135  if (memcmp(known_good_dst, dst, max_dst_size) != 0)
136  run_screaming("According to memcmp(), the compressed dst we got doesn't match the known_good_dst... ruh roh.", 1);
137  clock_gettime(CLOCK_MONOTONIC, &start);
138  for (int i=1; i<=iterations; i++)
139  LZ4_compress_default(src, dst, src_size, max_dst_size);
140  break;
141 
143  printf("Starting benchmark for function: LZ4_compress_fast()\n");
144  for(int junk=0; junk<warm_up; junk++)
145  rv = LZ4_compress_fast(src, dst, src_size, max_dst_size, acceleration);
146  if (rv < 1)
147  run_screaming("Couldn't run LZ4_compress_fast()... error code received is in exit code.", rv);
148  if (memcmp(known_good_dst, dst, max_dst_size) != 0)
149  run_screaming("According to memcmp(), the compressed dst we got doesn't match the known_good_dst... ruh roh.", 1);
150  clock_gettime(CLOCK_MONOTONIC, &start);
151  for (int i=1; i<=iterations; i++)
152  LZ4_compress_fast(src, dst, src_size, max_dst_size, acceleration);
153  break;
154 
156  printf("Starting benchmark for function: LZ4_compress_fast_extState()\n");
157  for(int junk=0; junk<warm_up; junk++)
158  rv = LZ4_compress_fast_extState(&state, src, dst, src_size, max_dst_size, acceleration);
159  if (rv < 1)
160  run_screaming("Couldn't run LZ4_compress_fast_extState()... error code received is in exit code.", rv);
161  if (memcmp(known_good_dst, dst, max_dst_size) != 0)
162  run_screaming("According to memcmp(), the compressed dst we got doesn't match the known_good_dst... ruh roh.", 1);
163  clock_gettime(CLOCK_MONOTONIC, &start);
164  for (int i=1; i<=iterations; i++)
165  LZ4_compress_fast_extState(&state, src, dst, src_size, max_dst_size, acceleration);
166  break;
167 
168 // Disabled until LZ4_compress_generic() is exposed in the header.
169 // case ID__LZ4_COMPRESS_GENERIC:
170 // printf("Starting benchmark for function: LZ4_compress_generic()\n");
171 // LZ4_resetStream((LZ4_stream_t*)&state);
172 // for(int junk=0; junk<warm_up; junk++) {
173 // LZ4_resetStream((LZ4_stream_t*)&state);
174 // //rv = LZ4_compress_generic_wrapper(&state, src, dst, src_size, max_dst_size, notLimited, byU16, noDict, noDictIssue, acceleration);
175 // LZ4_compress_generic_wrapper(&state, src, dst, src_size, max_dst_size, acceleration);
176 // }
177 // if (rv < 1)
178 // run_screaming("Couldn't run LZ4_compress_generic()... error code received is in exit code.", rv);
179 // if (memcmp(known_good_dst, dst, max_dst_size) != 0)
180 // run_screaming("According to memcmp(), the compressed dst we got doesn't match the known_good_dst... ruh roh.", 1);
181 // for (int i=1; i<=iterations; i++) {
182 // LZ4_resetStream((LZ4_stream_t*)&state);
183 // //LZ4_compress_generic_wrapper(&state, src, dst, src_size, max_dst_size, notLimited, byU16, noDict, noDictIssue, acceleration);
184 // LZ4_compress_generic_wrapper(&state, src, dst, src_size, max_dst_size, acceleration);
185 // }
186 // break;
187 
189  printf("Starting benchmark for function: LZ4_decompress_safe()\n");
190  for(int junk=0; junk<warm_up; junk++)
191  rv = LZ4_decompress_safe(src, dst, comp_size, src_size);
192  if (rv < 1)
193  run_screaming("Couldn't run LZ4_decompress_safe()... error code received is in exit code.", rv);
194  if (memcmp(known_good_dst, dst, src_size) != 0)
195  run_screaming("According to memcmp(), the compressed dst we got doesn't match the known_good_dst... ruh roh.", 1);
196  clock_gettime(CLOCK_MONOTONIC, &start);
197  for (int i=1; i<=iterations; i++)
198  LZ4_decompress_safe(src, dst, comp_size, src_size);
199  break;
200 
202  printf("Starting benchmark for function: LZ4_decompress_fast()\n");
203  for(int junk=0; junk<warm_up; junk++)
204  rv = LZ4_decompress_fast(src, dst, src_size);
205  if (rv < 1)
206  run_screaming("Couldn't run LZ4_decompress_fast()... error code received is in exit code.", rv);
207  if (memcmp(known_good_dst, dst, src_size) != 0)
208  run_screaming("According to memcmp(), the compressed dst we got doesn't match the known_good_dst... ruh roh.", 1);
209  clock_gettime(CLOCK_MONOTONIC, &start);
210  for (int i=1; i<=iterations; i++)
211  LZ4_decompress_fast(src, dst, src_size);
212  break;
213 
214  default:
215  run_screaming("The test specified isn't valid. Please check your code.", 1);
216  break;
217  }
218 
219  // Stop timer and return time taken.
220  clock_gettime(CLOCK_MONOTONIC, &end);
221  time_taken = BILLION *(end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec;
222 
223  return time_taken;
224 }
lzma_index ** i
Definition: index.h:629
lzma_index * src
Definition: index.h:567
#define BILLION
#define ID__LZ4_DECOMPRESS_SAFE
void run_screaming(const char *message, const int code)
#define ID__LZ4_DECOMPRESS_FAST
#define ID__LZ4_COMPRESS_FAST
#define ID__LZ4_COMPRESS_DEFAULT
#define ID__LZ4_COMPRESS_FAST_EXTSTATE
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
Definition: sflib.h:133
int LZ4_compress_fast_extState(void *state, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
Definition: lz4.c:1284
int LZ4_compress_default(const char *src, char *dst, int srcSize, int maxOutputSize)
Definition: lz4.c:1373
int LZ4_compress_fast(const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
Definition: lz4.c:1354
LZ4_FORCE_O2 int LZ4_decompress_fast(const char *source, char *dest, int originalSize)
Definition: lz4.c:2188
LZ4_FORCE_O2 int LZ4_decompress_safe(const char *source, char *dest, int compressedSize, int maxDecompressedSize)
Definition: lz4.c:2171
char * dst
Definition: lz4.h:724
unsigned long uint64_t
Definition: sftypes.h:28
Definition: dis.h:43

References BILLION, dst, test_evm::end, i, ID__LZ4_COMPRESS_DEFAULT, ID__LZ4_COMPRESS_FAST, ID__LZ4_COMPRESS_FAST_EXTSTATE, ID__LZ4_DECOMPRESS_FAST, ID__LZ4_DECOMPRESS_SAFE, LZ4_compress_default(), LZ4_compress_fast(), LZ4_compress_fast_extState(), LZ4_decompress_fast(), LZ4_decompress_safe(), printf(), run_screaming(), src, and start.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 236 of file compress_functions.c.

236  {
237  // Get and verify options. There's really only 1: How many iterations to run.
238  int iterations = 1000000;
239  if (argc > 1)
240  iterations = atoi(argv[1]);
241  if (iterations < 1)
242  usage("Argument 1 (iterations) must be > 0.");
243 
244  // First we will create 2 sources (char *) of 2000 bytes each. One normal text, the other highly-compressible text.
245  const char *src = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed luctus purus et risus vulputate, et mollis orci ullamcorper. Nulla facilisi. Fusce in ligula sed purus varius aliquet interdum vitae justo. Proin quis diam velit. Nulla varius iaculis auctor. Cras volutpat, justo eu dictum pulvinar, elit sem porttitor metus, et imperdiet metus sapien et ante. Nullam nisi nulla, ornare eu tristique eu, dignissim vitae diam. Nulla sagittis porta libero, a accumsan felis sagittis scelerisque. Integer laoreet eleifend congue. Etiam rhoncus leo vel dolor fermentum, quis luctus nisl iaculis. Praesent a erat sapien. Aliquam semper mi in lorem ultrices ultricies. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In feugiat risus sed enim ultrices, at sodales nulla tristique. Maecenas eget pellentesque justo, sed pellentesque lectus. Fusce sagittis sit amet elit vel varius. Donec sed ligula nec ligula vulputate rutrum sed ut lectus. Etiam congue pharetra leo vitae cursus. Morbi enim ante, porttitor ut varius vel, tincidunt quis justo. Nunc iaculis, risus id ultrices semper, metus est efficitur ligula, vel posuere risus nunc eget purus. Ut lorem turpis, condimentum at sem sed, porta aliquam turpis. In ut sapien a nulla dictum tincidunt quis sit amet lorem. Fusce at est egestas, luctus neque eu, consectetur tortor. Phasellus eleifend ultricies nulla ac lobortis. Morbi maximus quam cursus vehicula iaculis. Maecenas cursus vel justo ut rutrum. Curabitur magna orci, dignissim eget dapibus vitae, finibus id lacus. Praesent rhoncus mattis augue vitae bibendum. Praesent porta mauris non ultrices fermentum. Quisque vulputate ipsum in sodales pulvinar. Aliquam nec mollis felis. Donec vitae augue pulvinar, congue nisl sed, pretium purus. Fusce lobortis mi ac neque scelerisque semper. Pellentesque vel est vitae magna aliquet aliquet. Nam non dolor. Nulla facilisi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Morbi ac lacinia felis metus.";
246  const char *hc_src = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
247  // Set and derive sizes. Since we're using strings, use strlen() + 1 for \0.
248  const size_t src_size = strlen(src) + 1;
249  const size_t max_dst_size = LZ4_compressBound(src_size);
250  int bytes_returned = 0;
251  // Now build allocations for the data we'll be playing with.
252  char *dst = calloc(1, max_dst_size);
253  char *known_good_dst = calloc(1, max_dst_size);
254  char *known_good_hc_dst = calloc(1, max_dst_size);
255  if (dst == NULL || known_good_dst == NULL || known_good_hc_dst == NULL)
256  run_screaming("Couldn't allocate memory for the destination buffers. Sad :(", 1);
257 
258  // Create known-good buffers to verify our tests with other functions will produce the same results.
259  bytes_returned = LZ4_compress_default(src, known_good_dst, src_size, max_dst_size);
260  if (bytes_returned < 1)
261  run_screaming("Couldn't create a known-good destination buffer for comparison... this is bad.", 1);
262  const size_t src_comp_size = bytes_returned;
263  bytes_returned = LZ4_compress_default(hc_src, known_good_hc_dst, src_size, max_dst_size);
264  if (bytes_returned < 1)
265  run_screaming("Couldn't create a known-good (highly compressible) destination buffer for comparison... this is bad.", 1);
266  const size_t hc_src_comp_size = bytes_returned;
267 
268 
269  /* LZ4_compress_default() */
270  // This is the default function so we don't need to demonstrate how to use it. See basics.c if you need more basal information.
271 
272  /* LZ4_compress_fast() */
273  // Using this function is identical to LZ4_compress_default except we need to specify an "acceleration" value. Defaults to 1.
274  memset(dst, 0, max_dst_size);
275  bytes_returned = LZ4_compress_fast(src, dst, src_size, max_dst_size, 1);
276  if (bytes_returned < 1)
277  run_screaming("Failed to compress src using LZ4_compress_fast. echo $? for return code.", bytes_returned);
278  if (memcmp(dst, known_good_dst, bytes_returned) != 0)
279  run_screaming("According to memcmp(), the value we got in dst from LZ4_compress_fast doesn't match the known-good value. This is bad.", 1);
280 
281  /* LZ4_compress_fast_extState() */
282  // Using this function directly requires that we build an LZ4_stream_t struct ourselves. We do NOT have to reset it ourselves.
283  memset(dst, 0, max_dst_size);
285  bytes_returned = LZ4_compress_fast_extState(&state, src, dst, src_size, max_dst_size, 1);
286  if (bytes_returned < 1)
287  run_screaming("Failed to compress src using LZ4_compress_fast_extState. echo $? for return code.", bytes_returned);
288  if (memcmp(dst, known_good_dst, bytes_returned) != 0)
289  run_screaming("According to memcmp(), the value we got in dst from LZ4_compress_fast_extState doesn't match the known-good value. This is bad.", 1);
290 
291  /* LZ4_compress_generic */
292  // When you can exactly control the inputs and options of your LZ4 needs, you can use LZ4_compress_generic and fixed (const)
293  // values for the enum types such as dictionary and limitations. Any other direct-use is probably a bad idea.
294  //
295  // That said, the LZ4_compress_generic() function is 'static inline' and does not have a prototype in lz4.h to expose a symbol
296  // for it. In other words: we can't access it directly. I don't want to submit a PR that modifies lz4.c/h. Yann and others can
297  // do that if they feel it's worth expanding this example.
298  //
299  // I will, however, leave a skeleton of what would be required to use it directly:
300  /*
301  memset(dst, 0, max_dst_size);
302  // LZ4_stream_t state: is already declared above. We can reuse it BUT we have to reset the stream ourselves between each call.
303  LZ4_resetStream((LZ4_stream_t *)&state);
304  // Since src size is small we know the following enums will be used: notLimited (0), byU16 (2), noDict (0), noDictIssue (0).
305  bytes_returned = LZ4_compress_generic(&state, src, dst, src_size, max_dst_size, notLimited, byU16, noDict, noDictIssue, 1);
306  if (bytes_returned < 1)
307  run_screaming("Failed to compress src using LZ4_compress_generic. echo $? for return code.", bytes_returned);
308  if (memcmp(dst, known_good_dst, bytes_returned) != 0)
309  run_screaming("According to memcmp(), the value we got in dst from LZ4_compress_generic doesn't match the known-good value. This is bad.", 1);
310  */
311 
312 
313  /* Benchmarking */
314  /* Now we'll run a few rudimentary benchmarks with each function to demonstrate differences in speed based on the function used.
315  * Remember, we cannot call LZ4_compress_generic() directly (yet) so it's disabled.
316  */
317  // Suite A - Normal Compressibility
318  char *dst_d = calloc(1, src_size);
319  memset(dst, 0, max_dst_size);
320  printf("\nStarting suite A: Normal compressible text.\n");
321  uint64_t time_taken__default = bench(known_good_dst, ID__LZ4_COMPRESS_DEFAULT, iterations, src, dst, src_size, max_dst_size, src_comp_size);
322  uint64_t time_taken__fast = bench(known_good_dst, ID__LZ4_COMPRESS_FAST, iterations, src, dst, src_size, max_dst_size, src_comp_size);
323  uint64_t time_taken__fast_extstate = bench(known_good_dst, ID__LZ4_COMPRESS_FAST_EXTSTATE, iterations, src, dst, src_size, max_dst_size, src_comp_size);
324  //uint64_t time_taken__generic = bench(known_good_dst, ID__LZ4_COMPRESS_GENERIC, iterations, src, dst, src_size, max_dst_size, src_comp_size);
325  uint64_t time_taken__decomp_safe = bench(src, ID__LZ4_DECOMPRESS_SAFE, iterations, known_good_dst, dst_d, src_size, max_dst_size, src_comp_size);
326  uint64_t time_taken__decomp_fast = bench(src, ID__LZ4_DECOMPRESS_FAST, iterations, known_good_dst, dst_d, src_size, max_dst_size, src_comp_size);
327  // Suite B - Highly Compressible
328  memset(dst, 0, max_dst_size);
329  printf("\nStarting suite B: Highly compressible text.\n");
330  uint64_t time_taken_hc__default = bench(known_good_hc_dst, ID__LZ4_COMPRESS_DEFAULT, iterations, hc_src, dst, src_size, max_dst_size, hc_src_comp_size);
331  uint64_t time_taken_hc__fast = bench(known_good_hc_dst, ID__LZ4_COMPRESS_FAST, iterations, hc_src, dst, src_size, max_dst_size, hc_src_comp_size);
332  uint64_t time_taken_hc__fast_extstate = bench(known_good_hc_dst, ID__LZ4_COMPRESS_FAST_EXTSTATE, iterations, hc_src, dst, src_size, max_dst_size, hc_src_comp_size);
333  //uint64_t time_taken_hc__generic = bench(known_good_hc_dst, ID__LZ4_COMPRESS_GENERIC, iterations, hc_src, dst, src_size, max_dst_size, hc_src_comp_size);
334  uint64_t time_taken_hc__decomp_safe = bench(hc_src, ID__LZ4_DECOMPRESS_SAFE, iterations, known_good_hc_dst, dst_d, src_size, max_dst_size, hc_src_comp_size);
335  uint64_t time_taken_hc__decomp_fast = bench(hc_src, ID__LZ4_DECOMPRESS_FAST, iterations, known_good_hc_dst, dst_d, src_size, max_dst_size, hc_src_comp_size);
336 
337  // Report and leave.
338  setlocale(LC_ALL, "");
339  const char *format = "|%-14s|%-30s|%'14.9f|%'16d|%'14d|%'13.2f%%|\n";
340  const char *header_format = "|%-14s|%-30s|%14s|%16s|%14s|%14s|\n";
341  const char *separator = "+--------------+------------------------------+--------------+----------------+--------------+--------------+\n";
342  printf("\n");
343  printf("%s", separator);
344  printf(header_format, "Source", "Function Benchmarked", "Total Seconds", "Iterations/sec", "ns/Iteration", "% of default");
345  printf("%s", separator);
346  printf(format, "Normal Text", "LZ4_compress_default()", (double)time_taken__default / BILLION, (int)(iterations / ((double)time_taken__default /BILLION)), (int)time_taken__default / iterations, (double)time_taken__default * 100 / time_taken__default);
347  printf(format, "Normal Text", "LZ4_compress_fast()", (double)time_taken__fast / BILLION, (int)(iterations / ((double)time_taken__fast /BILLION)), (int)time_taken__fast / iterations, (double)time_taken__fast * 100 / time_taken__default);
348  printf(format, "Normal Text", "LZ4_compress_fast_extState()", (double)time_taken__fast_extstate / BILLION, (int)(iterations / ((double)time_taken__fast_extstate /BILLION)), (int)time_taken__fast_extstate / iterations, (double)time_taken__fast_extstate * 100 / time_taken__default);
349  //printf(format, "Normal Text", "LZ4_compress_generic()", (double)time_taken__generic / BILLION, (int)(iterations / ((double)time_taken__generic /BILLION)), (int)time_taken__generic / iterations, (double)time_taken__generic * 100 / time_taken__default);
350  printf(format, "Normal Text", "LZ4_decompress_safe()", (double)time_taken__decomp_safe / BILLION, (int)(iterations / ((double)time_taken__decomp_safe /BILLION)), (int)time_taken__decomp_safe / iterations, (double)time_taken__decomp_safe * 100 / time_taken__default);
351  printf(format, "Normal Text", "LZ4_decompress_fast()", (double)time_taken__decomp_fast / BILLION, (int)(iterations / ((double)time_taken__decomp_fast /BILLION)), (int)time_taken__decomp_fast / iterations, (double)time_taken__decomp_fast * 100 / time_taken__default);
352  printf(header_format, "", "", "", "", "", "");
353  printf(format, "Compressible", "LZ4_compress_default()", (double)time_taken_hc__default / BILLION, (int)(iterations / ((double)time_taken_hc__default /BILLION)), (int)time_taken_hc__default / iterations, (double)time_taken_hc__default * 100 / time_taken_hc__default);
354  printf(format, "Compressible", "LZ4_compress_fast()", (double)time_taken_hc__fast / BILLION, (int)(iterations / ((double)time_taken_hc__fast /BILLION)), (int)time_taken_hc__fast / iterations, (double)time_taken_hc__fast * 100 / time_taken_hc__default);
355  printf(format, "Compressible", "LZ4_compress_fast_extState()", (double)time_taken_hc__fast_extstate / BILLION, (int)(iterations / ((double)time_taken_hc__fast_extstate /BILLION)), (int)time_taken_hc__fast_extstate / iterations, (double)time_taken_hc__fast_extstate * 100 / time_taken_hc__default);
356  //printf(format, "Compressible", "LZ4_compress_generic()", (double)time_taken_hc__generic / BILLION, (int)(iterations / ((double)time_taken_hc__generic /BILLION)), (int)time_taken_hc__generic / iterations, (double)time_taken_hc__generic * 100 / time_taken_hc__default);
357  printf(format, "Compressible", "LZ4_decompress_safe()", (double)time_taken_hc__decomp_safe / BILLION, (int)(iterations / ((double)time_taken_hc__decomp_safe /BILLION)), (int)time_taken_hc__decomp_safe / iterations, (double)time_taken_hc__decomp_safe * 100 / time_taken_hc__default);
358  printf(format, "Compressible", "LZ4_decompress_fast()", (double)time_taken_hc__decomp_fast / BILLION, (int)(iterations / ((double)time_taken_hc__decomp_fast /BILLION)), (int)time_taken_hc__decomp_fast / iterations, (double)time_taken_hc__decomp_fast * 100 / time_taken_hc__default);
359  printf("%s", separator);
360  printf("\n");
361  printf("All done, ran %d iterations per test.\n", iterations);
362  return 0;
363 }
uint64_t bench(const char *known_good_dst, const int function_id, const int iterations, const char *src, char *dst, const size_t src_size, const size_t max_dst_size, const size_t comp_size)
void usage(const char *message)
#define NULL
Definition: cris-opc.c:27
return memset(p, 0, total)
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
int LZ4_compressBound(int isize)
Definition: lz4.c:674

References argv, bench(), BILLION, calloc(), dst, ID__LZ4_COMPRESS_DEFAULT, ID__LZ4_COMPRESS_FAST, ID__LZ4_COMPRESS_FAST_EXTSTATE, ID__LZ4_DECOMPRESS_FAST, ID__LZ4_DECOMPRESS_SAFE, LZ4_compress_default(), LZ4_compress_fast(), LZ4_compress_fast_extState(), LZ4_compressBound(), memset(), NULL, printf(), run_screaming(), src, and usage().

◆ run_screaming()

void run_screaming ( const char *  message,
const int  code 
)

Definition at line 89 of file compress_functions.c.

89  {
90  printf("%s\n", message);
91  exit(code);
92 }
Definition: inftree9.h:24
char * message
Definition: main.c:12

References test-lz4-list::exit, message, and printf().

Referenced by bench(), main(), and usage().

◆ usage()

void usage ( const char *  message)

Definition at line 98 of file compress_functions.c.

98  {
99  printf("Usage: ./argPerformanceTesting <iterations>\n");
101  return;
102 }

References message, printf(), and run_screaming().

Referenced by lzma_raw_coder_memusage(), main(), print_help(), and uv_getrusage().