-
Notifications
You must be signed in to change notification settings - Fork 12
/
crc32_bench.c
47 lines (38 loc) · 1.2 KB
/
crc32_bench.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Copyright (C) 2015 Anton Blanchard <anton@au.ibm.com>, IBM
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of either:
*
* a) the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version, or
* b) the Apache License, Version 2.0
*/
#include <malloc.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
unsigned int crc32_vpmsum(unsigned int crc, unsigned char *p, unsigned long len);
int main(int argc, char *argv[])
{
unsigned long length, iterations;
unsigned char *data;
unsigned long i;
unsigned int crc = 0;
if (argc != 3) {
fprintf(stderr, "Usage: %s length iterations\n", argv[0]);
fprintf(stderr, "Performs crc32 checksum an [iterations] number of times on a buffer filled with junk data of [length] bytes\n");
exit(1);
}
length = strtoul(argv[1], NULL, 0);
iterations = strtoul(argv[2], NULL, 0);
data = memalign(getpagesize(), length);
srandom(1);
for (i = 0; i < length; i++)
data[i] = random() & 0xff;
for (i = 0; i < iterations; i++)
crc = crc32_vpmsum(crc, data, length);
printf("CRC: %08x\n", crc);
return 0;
}