55 #if __STDC_VERSION__ >= 199901L
56 #define _XOPEN_SOURCE 600
58 #define _XOPEN_SOURCE 500
60 #define _POSIX_C_SOURCE 199309L
63 #define LZ4_DISABLE_DEPRECATE_WARNINGS
74 #define BILLION 1000000000L
77 #define ID__LZ4_COMPRESS_DEFAULT 1
78 #define ID__LZ4_COMPRESS_FAST 2
79 #define ID__LZ4_COMPRESS_FAST_EXTSTATE 3
80 #define ID__LZ4_COMPRESS_GENERIC 4
81 #define ID__LZ4_DECOMPRESS_SAFE 5
82 #define ID__LZ4_DECOMPRESS_FAST 6
99 printf(
"Usage: ./argPerformanceTesting <iterations>\n");
110 const char *known_good_dst,
111 const int function_id,
112 const int iterations,
115 const size_t src_size,
116 const size_t max_dst_size,
117 const size_t comp_size
121 const int warm_up = 5000;
123 const int acceleration = 1;
128 switch(function_id) {
130 printf(
"Starting benchmark for function: LZ4_compress_default()\n");
131 for(
int junk=0; junk<warm_up; junk++)
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++)
143 printf(
"Starting benchmark for function: LZ4_compress_fast()\n");
144 for(
int junk=0; junk<warm_up; junk++)
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++)
156 printf(
"Starting benchmark for function: LZ4_compress_fast_extState()\n");
157 for(
int junk=0; junk<warm_up; junk++)
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++)
189 printf(
"Starting benchmark for function: LZ4_decompress_safe()\n");
190 for(
int junk=0; junk<warm_up; junk++)
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++)
202 printf(
"Starting benchmark for function: LZ4_decompress_fast()\n");
203 for(
int junk=0; junk<warm_up; junk++)
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++)
215 run_screaming(
"The test specified isn't valid. Please check your code.", 1);
220 clock_gettime(CLOCK_MONOTONIC, &
end);
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 =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
248 const size_t src_size = strlen(
src) + 1;
250 int bytes_returned = 0;
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);
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);
int main(int argc, char **argv)
#define ID__LZ4_DECOMPRESS_SAFE
void run_screaming(const char *message, const int code)
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)
#define ID__LZ4_DECOMPRESS_FAST
#define ID__LZ4_COMPRESS_FAST
void usage(const char *message)
#define ID__LZ4_COMPRESS_DEFAULT
#define ID__LZ4_COMPRESS_FAST_EXTSTATE
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
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
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_compress_fast_extState(void *state, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
int LZ4_compressBound(int isize)
int LZ4_compress_default(const char *src, char *dst, int srcSize, int maxOutputSize)
int LZ4_compress_fast(const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
LZ4_FORCE_O2 int LZ4_decompress_fast(const char *source, char *dest, int originalSize)
LZ4_FORCE_O2 int LZ4_decompress_safe(const char *source, char *dest, int compressedSize, int maxDecompressedSize)