-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathztest.c
More file actions
76 lines (63 loc) · 1.7 KB
/
ztest.c
File metadata and controls
76 lines (63 loc) · 1.7 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include "types.h"
void test_coreutils_1(char *buf, size_t size);
void test_coreutils_3(char *buf, size_t size);
void test_haskell(char *buf, size_t size);
void test_nayuki(char *buf, size_t size);
void test_openssl_1(char *buf, size_t size);
void test_openssl_3(char *buf, size_t size);
void test_openssl_biomem(char *buf, size_t size);
void test_openssl_biofile(char * fname);
void test_sph(char *buf, size_t size);
timestamp_t
timestamp()
{
struct timeval now;
gettimeofday(&now, NULL);
return (timestamp_t) now.tv_sec * 1000000 + now.tv_usec;
}
void
report(char * name, unsigned char * res, timestamp_t usecs)
{
printf("%llu\t", usecs);
for (int i = 0; i < SHA1_OUTPUT_LEN; i++)
printf("%02x", res[i]);
printf("\t%s\n", name);
}
void
test_func(char * fname, size_t fsize, void (*func)(char *, size_t))
{
int fd = open(fname, O_RDONLY);
char * buf = mmap(NULL, fsize, PROT_READ, MAP_PRIVATE, fd, 0);
madvise(buf, fsize, MADV_SEQUENTIAL);
func(buf, fsize);
close(fd);
}
int
main(int argc, char ** argv)
{
if (argc == 1) {
fprintf(stderr, "Usage: %s <filename>\n", *argv);
exit(1);
}
struct stat argstat;
stat(*++argv, &argstat);
#define TEST_FUNC(f) test_func(*argv, argstat.st_size, f)
TEST_FUNC(test_coreutils_1);
TEST_FUNC(test_coreutils_3);
TEST_FUNC(test_nayuki);
TEST_FUNC(test_openssl_1);
TEST_FUNC(test_openssl_3);
// TEST_FUNC(test_openssl_biomem);
TEST_FUNC(test_sph);
TEST_FUNC(test_haskell);
// test_openssl_biofile(*argv);
exit(0);
}