-
Notifications
You must be signed in to change notification settings - Fork 0
/
sha2-benchmark.c
104 lines (85 loc) · 2.29 KB
/
sha2-benchmark.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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* LTTng-UST benchmarks
* Copyright (C) 2013 Samuel Demers <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include "sha2.h"
#include "shared_events.h"
#ifdef WITH_UST
#include <lttng/tracepoint.h>
#include "message.tp.h"
#endif
#define BUFFER_SIZE (1<<10)
#define HASH_SIZE 32
/*
* input_buffer is updated within the loop so the compiler cannot assume
* it is unchanged between loops.
*/
static unsigned char input_buffer[BUFFER_SIZE];
static
void print_usage(int argc, char **argv)
{
fprintf(stderr, "Usage: %s [<iterations>]\n", argv[0]);
}
static
void update_buffer(unsigned char *buffer, size_t len, unsigned int v)
{
unsigned int i;
for (i = 0; i < len; i++) {
input_buffer[i] = v ^ i;
}
}
int main(int argc, char **argv)
{
unsigned char hash[HASH_SIZE];
long iterations;
sha2_context ctx;
unsigned int i;
if (shared_events_add("main")) {
exit(EXIT_FAILURE);
}
if (argc == 1) {
// We may just want to measure process startup time
exit(EXIT_SUCCESS);
}
if (argc > 2) {
print_usage(argc, argv);
exit(EXIT_FAILURE);
}
iterations = strtol(argv[1], (char **) NULL, 10);
if (iterations <= 0) {
print_usage(argc, argv);
exit(EXIT_FAILURE);
}
sha2_starts(&ctx, 0);
if (shared_events_add("start")) {
exit(EXIT_FAILURE);
}
for (i = 0; i < iterations; i++) {
update_buffer(input_buffer, BUFFER_SIZE, i);
sha2_update(&ctx, input_buffer, BUFFER_SIZE);
#ifdef WITH_UST
tracepoint(benchmark_tracepoint, message, "Hello");
#endif
}
if (shared_events_add("end")) {
exit(EXIT_FAILURE);
}
sha2_finish(&ctx, hash);
exit(EXIT_SUCCESS);
}