Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: src/platform/vboot_reference/tests/sha_benchmark.c

Issue 596079: SHA* digest function speed test. (Closed)
Patch Set: Add explicit type cast. Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
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 <stdio.h>
7 #include <stdlib.h>
8
9 #include "sha.h"
10 #include "timer_utils.h"
11 #include "utility.h"
12
13 #define NUM_HASH_ALGORITHMS 3
14 #define TEST_BUFFER_SIZE 4000000
15
16 /* Table of hash function pointers and their description. */
17 typedef uint8_t* (*Hashptr) (const uint8_t*, int, uint8_t*);
18 typedef struct HashFxTable {
19 Hashptr hash;
20 char* description;
21 } HashFxTable;
22
23 HashFxTable hash_functions[NUM_HASH_ALGORITHMS] = {
24 {SHA1, "SHA1"},
25 {SHA256, "SHA256"},
26 {SHA512, "SHA512"}
27 };
28
29 int main(int argc, char* argv[]) {
30 int i;
31 double speed;
32 uint32_t msecs;
33 uint8_t* buffer = (uint8_t*) Malloc(TEST_BUFFER_SIZE);
34 uint8_t* digest = (uint8_t*) Malloc(SHA512_DIGEST_SIZE); /* Maximum size of
35 * the digest. */
36 ClockTimerState ct;
37
38 /* Iterate through all the hash functions. */
39 for(i = 0; i < NUM_HASH_ALGORITHMS; i++) {
40 StartTimer(&ct);
41 hash_functions[i].hash(buffer, TEST_BUFFER_SIZE, digest);
42 StopTimer(&ct);
43
44 msecs = GetDurationMsecs(&ct);
45 speed = ((TEST_BUFFER_SIZE / 10e6)
46 / (msecs / 10e3)); /* Mbytes/sec */
47
48 fprintf(stderr, "%s Time taken = %u ms, Speed = %f Mbytes/sec\n",
49 hash_functions[i].description, msecs, speed);
50 }
51
52 Free(digest);
53 Free(buffer);
54 return 0;
55 }
OLDNEW
« no previous file with comments | « src/platform/vboot_reference/tests/Makefile ('k') | src/platform/vboot_reference/tests/timer_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698