Blame src/benchmark.h

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