sha_benchmark.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Copyright (c) 2011 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. #include <stdint.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include "2sysincludes.h"
  9. #include "2common.h"
  10. #include "2sha.h"
  11. #include "host_common.h"
  12. #include "timer_utils.h"
  13. #define TEST_BUFFER_SIZE 4000000
  14. int main(int argc, char *argv[]) {
  15. int i;
  16. double speed;
  17. uint32_t msecs;
  18. uint8_t *buffer = malloc(TEST_BUFFER_SIZE);
  19. uint8_t digest[VB2_MAX_DIGEST_SIZE];
  20. ClockTimerState ct;
  21. /* Iterate through all the hash functions. */
  22. for(i = VB2_HASH_SHA1; i < VB2_HASH_ALG_COUNT; i++) {
  23. StartTimer(&ct);
  24. vb2_digest_buffer(buffer, TEST_BUFFER_SIZE, i,
  25. digest, sizeof(digest));
  26. StopTimer(&ct);
  27. msecs = GetDurationMsecs(&ct);
  28. speed = ((TEST_BUFFER_SIZE / 10e6)
  29. / (msecs / 10e3)); /* Mbytes/sec */
  30. fprintf(stderr,
  31. "# %s Time taken = %u ms, Speed = %f Mbytes/sec\n",
  32. vb2_get_hash_algorithm_name(i), msecs, speed);
  33. fprintf(stdout, "mbytes_per_sec_%s:%f\n",
  34. vb2_get_hash_algorithm_name(i), speed);
  35. }
  36. free(buffer);
  37. return 0;
  38. }