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