238 int iterations = 1000000;
240 iterations = atoi(
argv[1]);
242 usage(
"Argument 1 (iterations) must be > 0.");
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 =
"aaaaaaaaaaaaaa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
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);
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;
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;
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);
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);
318 char *dst_d =
calloc(1, src_size);
320 printf(
"\nStarting suite A: Normal compressible text.\n");
329 printf(
"\nStarting suite B: Highly compressible text.\n");
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";
344 printf(header_format,
"Source",
"Function Benchmarked",
"Total Seconds",
"Iterations/sec",
"ns/Iteration",
"% of default");
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);
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);
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);
361 printf(
"All done, ran %d iterations per test.\n", iterations);
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)
return memset(p, 0, total)
void * calloc(size_t number, size_t size)
static static fork const void static count static fd const char const char static newpath char char argv
int LZ4_compressBound(int isize)