File: benchmark-uhash.c

package info (click to toggle)
fastd 22-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,872 kB
  • sloc: asm: 15,114; ansic: 11,284; yacc: 599; sh: 472; makefile: 160; python: 35; perl: 11
file content (64 lines) | stat: -rw-r--r-- 1,553 bytes parent folder | download | duplicates (2)
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
// SPDX-License-Identifier: BSD-2-Clause
/*
  Copyright (c) 2012-2020, Matthias Schiffer <mschiffer@universe-factory.net>
  All rights reserved.
*/


#include "alloc.h"
#include "log.h"
#include "uhash-common.h"

#include <inttypes.h>
#include <stdio.h>


static int64_t get_time(void) {
	struct timespec ts;
	clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);

	return (1000 * (int64_t)ts.tv_sec) + ts.tv_nsec / 1000000;
}

static void run_benchmark(fastd_mac_state_t *mac_state, size_t iters, size_t size) {
	printf("Running %zd iterations with input size %zd... ", iters, size);

	size_t allocsize = alignto(size, 16);
	fastd_block128_t *inblocks = fastd_alloc_aligned(allocsize, 16);
	memset(inblocks, 0, allocsize);

	fastd_block128_t tag;

	int64_t start = get_time();
	for (size_t i = 0; i < iters; i++) {
		bool ok = fastd_mac_uhash_builtin.digest(mac_state, &tag, inblocks, size);
		if (!ok)
			exit_bug("uhash failed");
	}

	int64_t end = get_time();

	printf("done in %" PRId64 " ms\n", end - start);
}


int main(void) {
	if (&fastd_mac_uhash_builtin == NULL) {
		return 77;
	}

	fastd_mac_state_t *mac_state = fastd_mac_uhash_builtin.init(key, 0);

	run_benchmark(mac_state, 100000000, 20);
	run_benchmark(mac_state, 100000000, 100);
	run_benchmark(mac_state, 50000000, 300);
	run_benchmark(mac_state, 20000000, 1000);
	run_benchmark(mac_state, 10000000, 1500);
	run_benchmark(mac_state, 5000000, 2000);
	run_benchmark(mac_state, 5000000, 5000);
	run_benchmark(mac_state, 2000000, 10000);

	fastd_mac_uhash_builtin.free(mac_state);

	return 0;
}