1 /* Copyright 2011 The ChromiumOS Authors
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6 #include <stdint.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #include "2common.h"
11 #include "2sha.h"
12 #include "2sysincludes.h"
13 #include "common/timer_utils.h"
14 #include "host_common.h"
15
16 #define TEST_BUFFER_SIZE 4000000
17
main(int argc,char * argv[])18 int main(int argc, char *argv[]) {
19 int i;
20 double speed;
21 uint32_t msecs;
22 uint8_t *buffer = malloc(TEST_BUFFER_SIZE);
23 struct vb2_hash hash;
24 ClockTimerState ct;
25
26 /* Iterate through all the hash functions. */
27 for (i = VB2_HASH_SHA1; i < VB2_HASH_ALG_COUNT; i++) {
28 StartTimer(&ct);
29 vb2_hash_calculate(false, buffer, TEST_BUFFER_SIZE, i, &hash);
30 StopTimer(&ct);
31
32 msecs = GetDurationMsecs(&ct);
33 speed = ((TEST_BUFFER_SIZE / 10e6)
34 / (msecs / 10e3)); /* Mbytes/sec */
35
36 fprintf(stderr,
37 "# %s Time taken = %u ms, Speed = %f Mbytes/sec\n",
38 vb2_get_hash_algorithm_name(i), msecs, speed);
39 fprintf(stdout, "mbytes_per_sec_%s:%f\n",
40 vb2_get_hash_algorithm_name(i), speed);
41 }
42
43 free(buffer);
44 return 0;
45 }
46