Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 48 lines (41 sloc) 0.816 kB
b65bc21 Makefile: add framework to verify and bench sha1 implementations.
Junio C Hamano authored
1 #include "cache.h"
2
3 int main(int ac, char **av)
4 {
9126f00 fix openssl headers conflicting with custom SHA1 implementations
Nicolas Pitre authored
5 git_SHA_CTX ctx;
b65bc21 Makefile: add framework to verify and bench sha1 implementations.
Junio C Hamano authored
6 unsigned char sha1[20];
b57cbbf test-sha1: test hashing large buffer
Junio C Hamano authored
7 unsigned bufsz = 8192;
8 char *buffer;
9
10 if (ac == 2)
11 bufsz = strtoul(av[1], NULL, 10) * 1024 * 1024;
12
13 if (!bufsz)
14 bufsz = 8192;
15
16 while ((buffer = malloc(bufsz)) == NULL) {
17 fprintf(stderr, "bufsz %u is too big, halving...\n", bufsz);
18 bufsz /= 2;
19 if (bufsz < 1024)
20 die("OOPS");
21 }
b65bc21 Makefile: add framework to verify and bench sha1 implementations.
Junio C Hamano authored
22
9126f00 fix openssl headers conflicting with custom SHA1 implementations
Nicolas Pitre authored
23 git_SHA1_Init(&ctx);
b65bc21 Makefile: add framework to verify and bench sha1 implementations.
Junio C Hamano authored
24
25 while (1) {
b57cbbf test-sha1: test hashing large buffer
Junio C Hamano authored
26 ssize_t sz, this_sz;
27 char *cp = buffer;
28 unsigned room = bufsz;
29 this_sz = 0;
30 while (room) {
31 sz = xread(0, cp, room);
32 if (sz == 0)
33 break;
34 if (sz < 0)
d824cbb @trast Convert existing die(..., strerror(errno)) to die_errno()
trast authored
35 die_errno("test-sha1");
b57cbbf test-sha1: test hashing large buffer
Junio C Hamano authored
36 this_sz += sz;
37 cp += sz;
38 room -= sz;
39 }
40 if (this_sz == 0)
b65bc21 Makefile: add framework to verify and bench sha1 implementations.
Junio C Hamano authored
41 break;
9126f00 fix openssl headers conflicting with custom SHA1 implementations
Nicolas Pitre authored
42 git_SHA1_Update(&ctx, buffer, this_sz);
b65bc21 Makefile: add framework to verify and bench sha1 implementations.
Junio C Hamano authored
43 }
9126f00 fix openssl headers conflicting with custom SHA1 implementations
Nicolas Pitre authored
44 git_SHA1_Final(sha1, &ctx);
b65bc21 Makefile: add framework to verify and bench sha1 implementations.
Junio C Hamano authored
45 puts(sha1_to_hex(sha1));
46 exit(0);
47 }
Something went wrong with that request. Please try again.