summaryrefslogtreecommitdiffstats
path: root/moon-abe/pbc-0.5.14/guru/timefp.c
blob: 6e308f9a39e4799f0898bb088ca543002a58573d (plain)
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
#include "pbc.h"
#include "pbc_fp.h"
#include "pbc_test.h"

static void timefield(field_t fp) {
  int i, n;
  double t0, t1;

  element_t x, y, z;
  element_init(x, fp);
  element_init(y, fp);
  element_init(z, fp);

  element_random(x);
  element_random(y);

  n = 20000;
  t0 = pbc_get_time();
  for (i=0; i<n; i++) {
    element_mul(z, x, y);
    element_mul(x, y, z);
    element_mul(y, z, x);
  }
  t1 = pbc_get_time();
  printf("mul %fs\n", t1 - t0);

  n = 20000;
  t0 = pbc_get_time();
  for (i=0; i<n; i++) {
    element_square(x, x);
  }
  t1 = pbc_get_time();
  printf("square %fs\n", t1 - t0);

  n = 1000;
  t0 = pbc_get_time();
  for (i=0; i<n; i++) {
    element_invert(z, x);
    element_invert(z, y);
  }
  t1 = pbc_get_time();
  printf("invert %fs\n", t1 - t0);

  n = 40000;
  t0 = pbc_get_time();
  for (i=0; i<n; i++) {
    element_set0(z);
  }
  t1 = pbc_get_time();
  printf("set0 %fs\n", t1 - t0);

  n = 40000;
  t0 = pbc_get_time();
  for (i=0; i<n; i++) {
    element_set(z, x);
    element_set(z, y);
  }
  t1 = pbc_get_time();
  printf("set %fs\n", t1 - t0);

  n = 400;
  t0 = pbc_get_time();
  for (i=0; i<n; i++) {
    element_pow_zn(x, y, z);
  }
  t1 = pbc_get_time();
  printf("pow_zn %fs\n", t1 - t0);

  element_clear(x);
  element_clear(y);
  element_clear(z);
}

int main(int argc, char **argv) {
  field_t f1, f2;
  mpz_t prime;

  mpz_init(prime);
  if (argc > 1) {
    mpz_setbit(prime, atoi(argv[1]));
  } else {
    mpz_setbit(prime, 201);
  }
  mpz_setbit(prime, 70);
  mpz_nextprime(prime, prime);
  field_init_mont_fp(f1, prime);
  field_init_faster_fp(f2, prime);

  printf("montfp.c\n");
  timefield(f1);
  printf("fasterfp.c\n");
  timefield(f2);

  mpz_clear(prime);
  field_clear(f1);
  field_clear(f2);
  return 0;
}