Upgrade to libtasn1 4.19.0
[platform/upstream/libtasn1.git] / src / benchmark.h
1 /*
2  * Copyright (C) 2011-2022 Free Software Foundation, Inc.
3  *
4  * This file is part of GnuTLS.
5  *
6  * GnuTLS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GnuTLS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef BENCHMARK_H
21 # define BENCHMARK_H
22
23 # include <sys/time.h>
24 # include <time.h>
25 # include <signal.h>
26 # if defined _WIN32
27 #  include <windows.h>
28 # endif
29 # include <time.h>
30 # include "timespec.h"          /* gnulib gettime */
31
32 typedef void (*sighandler_t) (int);
33
34 struct benchmark_st
35 {
36   struct timespec start;
37   unsigned long size;
38   sighandler_t old_handler;
39 # if defined _WIN32
40   HANDLE wtimer;
41   HANDLE wthread;
42   LARGE_INTEGER alarm_timeout;
43 # endif
44 };
45
46 extern int benchmark_must_finish;
47
48 void start_benchmark (struct benchmark_st *st);
49 double stop_benchmark (struct benchmark_st *st, const char *metric);
50
51 inline static unsigned int
52 timespec_sub_ms (struct timespec *a, struct timespec *b)
53 {
54   return (a->tv_sec * 1000 + a->tv_nsec / (1000 * 1000) -
55           (b->tv_sec * 1000 + b->tv_nsec / (1000 * 1000)));
56 }
57
58 #endif /* BENCHMARK_H */