|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2011-2012 Free Software Foundation, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is free software: you can redistribute it and/or modify
|
|
Packit Service |
4684c1 |
* it under the terms of the GNU General Public License as published by
|
|
Packit Service |
4684c1 |
* the Free Software Foundation, either version 3 of the License, or
|
|
Packit Service |
4684c1 |
* (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is distributed in the hope that it will be useful,
|
|
Packit Service |
4684c1 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
4684c1 |
* GNU General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
4684c1 |
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifndef GNUTLS_SRC_BENCHMARK_H
|
|
Packit Service |
4684c1 |
#define GNUTLS_SRC_BENCHMARK_H
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <sys/time.h>
|
|
Packit Service |
4684c1 |
#include <time.h>
|
|
Packit Service |
4684c1 |
#include <signal.h>
|
|
Packit Service |
4684c1 |
#if defined(_WIN32)
|
|
Packit Service |
4684c1 |
#include <windows.h>
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* for uint64_t */
|
|
Packit Service |
4684c1 |
# include <stdint.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID)
|
|
Packit Service |
4684c1 |
#undef gettime
|
|
Packit Service |
4684c1 |
#define gettime(x) clock_gettime(CLOCK_PROCESS_CPUTIME_ID, x)
|
|
Packit Service |
4684c1 |
#else
|
|
Packit Service |
4684c1 |
inline static void gettime(struct timespec *ts)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
struct timeval tv;
|
|
Packit Service |
4684c1 |
gettimeofday(&tv, NULL);
|
|
Packit Service |
4684c1 |
ts->tv_sec = tv.tv_sec;
|
|
Packit Service |
4684c1 |
ts->tv_nsec = tv.tv_usec * 1000;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
typedef void (*sighandler_t) (int);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void benchmark_cipher(int debug_level);
|
|
Packit Service |
4684c1 |
void benchmark_tls(int debug_level, int ciphers);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
struct benchmark_st {
|
|
Packit Service |
4684c1 |
struct timespec start;
|
|
Packit Service |
4684c1 |
uint64_t size;
|
|
Packit Service |
4684c1 |
sighandler_t old_handler;
|
|
Packit Service |
4684c1 |
#if defined(_WIN32)
|
|
Packit Service |
4684c1 |
HANDLE wtimer;
|
|
Packit Service |
4684c1 |
HANDLE wthread;
|
|
Packit Service |
4684c1 |
LARGE_INTEGER alarm_timeout;
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
extern volatile int benchmark_must_finish;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void start_benchmark(struct benchmark_st *st);
|
|
Packit Service |
4684c1 |
double stop_benchmark(struct benchmark_st *st, const char *metric,
|
|
Packit Service |
4684c1 |
int quiet);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static unsigned int
|
|
Packit Service |
4684c1 |
timespec_sub_ms(struct timespec *a, struct timespec *b)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
return (a->tv_sec - b->tv_sec) * 1000 + (a->tv_nsec - b->tv_nsec) / (1000 * 1000);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
inline static unsigned long
|
|
Packit Service |
4684c1 |
timespec_sub_ns(struct timespec *a, struct timespec *b)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
return (a->tv_sec - b->tv_sec) * 1000000000 + (a->tv_nsec - b->tv_nsec);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#endif /* GNUTLS_SRC_BENCHMARK_H */
|