153
153
static void usage(const char* name)
155
155
printf("%s %s: run a string related benchmark.\n"
156
"usage: %s [-c block-size] [-l loop-count] [-a alignment] [-f] [-t test-name]\n"
156
"usage: %s [-c block-size] [-l loop-count] [-a alignment|src_alignment:dst_alignment] [-f] [-t test-name]\n"
157
157
, name, VERSION, name);
159
159
printf("Tests:");
192
#define MIN_BUFFER_SIZE 1024*1024
193
#define MAX_ALIGNMENT 256
192
195
/** Take a pointer and ensure that the lower bits == alignment */
193
196
static char *realign(char *p, int alignment)
200
198
uintptr_t pp = (uintptr_t)p;
201
pp = (pp + 255) & ~255;
199
pp = (pp + (MAX_ALIGNMENT - 1)) & ~(MAX_ALIGNMENT - 1);
204
202
return (char *)pp;
207
#define MIN_BUFFER_SIZE 1024*1024
205
static int parse_int_arg(const char *arg, const char *exe_name)
210
ret = strtol(arg, NULL, 0);
220
static void parse_alignment_arg(const char *arg, const char *exe_name,
221
int *src_alignment, int *dst_alignment)
227
ret = strtol(arg, &endptr, 0);
234
*src_alignment = (int)ret;
236
if (ret > 256 || ret < 1)
238
printf("Alignment should be in the range [1, 256].\n");
245
if (endptr && *endptr == ':')
248
ret = strtol(endptr + 1, NULL, 0);
255
if (ret > 256 || ret < 1)
257
printf("Alignment should be in the range [1, 256].\n");
265
*dst_alignment = (int)ret;
209
268
/** Setup and run a test */
210
269
int main(int argc, char **argv)
233
count = atoi(optarg);
293
count = parse_int_arg(optarg, argv[0]);
236
loops = atoi(optarg);
296
loops = parse_int_arg(optarg, argv[0]);
239
alignment = atoi(optarg);
299
parse_alignment_arg(optarg, argv[0], &src_alignment, &dst_alignment);
264
if (alignment > 256 || alignment < 1)
266
printf("Alignment should be in the range [1, 256].\n");
270
if (alignment == 256)
273
if (count + alignment + 256 > MIN_BUFFER_SIZE)
275
buffer_size = count + alignment + 256;
324
if (count + MAX_ALIGNMENT * 2 > MIN_BUFFER_SIZE)
326
buffer_size = count + MAX_ALIGNMENT * 2;
278
329
/* Buffers to read and write from */
282
333
assert(src != NULL && dest != NULL);
284
src = realign(src, alignment);
285
dest = realign(dest, alignment);
335
src = realign(src, src_alignment);
336
dest = realign(dest, dst_alignment);
287
338
/* Fill the buffer with non-zero, reproducable random data */
340
391
double bounced = 0.448730 * loops / 50000000;
342
393
/* Dump both machine and human readable versions */
343
printf("%s:%s:%u:%u:%d:%.6f: took %.6f s for %u calls to %s of %u bytes. ~%.3f MB/s corrected.\n",
394
printf("%s:%s:%u:%u:%d:%d:%.6f: took %.6f s for %u calls to %s of %u bytes. ~%.3f MB/s corrected.\n",
344
395
variant + 4, ptest->name,
345
count, loops, alignment,
396
count, loops, src_alignment, dst_alignment,
347
398
elapsed, loops, ptest->name, count,
348
399
(double)loops*count/(elapsed - bounced)/(1024*1024));