bench.c 1.06 KB
Newer Older
Michael Meyer's avatar
Michael Meyer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <assert.h>

#include "u512.h"
#include "fp.h"
#include "mont.h"
#include "csidh.h"

#include <inttypes.h>

static __inline__ uint64_t rdtsc(void)
{
    uint32_t hi, lo;
    __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
    return lo | (uint64_t) hi << 32;
}

Fabio Campos's avatar
Fabio Campos committed
22
unsigned long its = 1000;
Michael Meyer's avatar
Michael Meyer committed
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

int main()
{
    clock_t t0, t1, time = 0;
    uint64_t c0, c1, cycles = 0;

    private_key priv;
    public_key pub = base;

    for (unsigned long i = 0; i < its; ++i) {

        csidh_private(&priv);

        t0 = clock();
        c0 = rdtsc();

        /**************************************/
        assert(validate(&pub));
        action(&pub, &pub, &priv);
        /**************************************/

        c1 = rdtsc();
        t1 = clock();
        cycles += c1 - c0;
        time += t1 - t0;
    }

    printf("iterations: %lu\n", its);
    printf("clock cycles: %" PRIu64 "\n", (uint64_t) cycles / its);
    printf("wall-clock time: %.3lf ms\n", 1000. * time / CLOCKS_PER_SEC / its);
}