File: timing.C

package info (click to toggle)
sfs 1%3A0.8-0%2Bpre20060720.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,668 kB
  • ctags: 14,317
  • sloc: cpp: 78,358; ansic: 15,494; sh: 9,540; yacc: 786; makefile: 706; perl: 676; lex: 553; python: 146; sed: 70
file content (42 lines) | stat: -rw-r--r-- 1,045 bytes parent folder | download | duplicates (3)
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
#include "arc4.h"
#include "sha1.h"

const char key[] = "secret key";
const int trials = 1024 * 8;
const int bufsize = 1024;
typedef unsigned char hash_t[160];

int main ()
{
  arc4 a;
  hash_t h;
  char buffer[bufsize];
  struct timeval start, end;

  sha1_hash (h, key, sizeof (key));
  a.setkey (h, sizeof (h));

  gettimeofday (&start, NULL);
  char *e = buffer + sizeof (buffer);
  for (int i = 0; i < trials; i++)
    for (char *p = &buffer[0]; p < e; p++)
      *p ^= a.getbyte ();
  gettimeofday (&end, NULL);

  long long diff = (end.tv_sec * 1000000 + end.tv_usec) - 
    (start.tv_sec * 1000000 + start.tv_usec);

  printf ("Encryption Rate %g KB/s\n",
	  (trials * bufsize / 1000.0) / (diff / 1000000.0));

  gettimeofday (&start, NULL);
  for (int i = 0; i < trials; i++)
    sha1_hash (h, buffer, sizeof (buffer));
  gettimeofday (&end, NULL);

  diff = (end.tv_sec * 1000000 + end.tv_usec) - 
    (start.tv_sec * 1000000 + start.tv_usec);

  printf ("SHA-1 Rate %g KB/s\n",
	  (trials * bufsize / 1000.0) / (diff / 1000000.0));
}