Commit db40330d authored by Stefan Westerfeld's avatar Stefan Westerfeld

Move performance test helper get_time() to utils.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent fb54737c
......@@ -21,20 +21,10 @@
#include <random>
#include <assert.h>
#include <sys/time.h>
using std::vector;
using std::string;
static double
gettime()
{
timeval tv;
gettimeofday (&tv, 0);
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
vector<int>
generate_error_vector (size_t n, int errors)
{
......@@ -210,14 +200,14 @@ main (int argc, char **argv)
while (in_bits.size() != 128)
in_bits.push_back (rand() & 1);
const double start_t = gettime();
const double start_t = get_time();
const size_t runs = 20;
for (size_t i = 0; i < runs; i++)
{
vector<int> out_bits = conv_decode_hard (block_type, conv_encode (block_type, in_bits));
assert (out_bits == in_bits);
}
printf ("%.1f ms/block\n", (gettime() - start_t) / runs * 1000.0);
printf ("%.1f ms/block\n", (get_time() - start_t) / runs * 1000.0);
}
if (argc == 3 && string (argv[2]) == "table")
conv_print_table (block_type);
......
......@@ -21,7 +21,6 @@
#include <assert.h>
#include <math.h>
#include <string.h>
#include <sys/time.h>
#include "sfinputstream.hh"
#include "sfoutputstream.hh"
......@@ -33,15 +32,6 @@ using std::vector;
using std::max;
using std::min;
static double
gettime()
{
timeval tv;
gettimeofday (&tv, 0);
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
int
perf()
{
......@@ -52,13 +42,13 @@ perf()
vector<float> samples (2 * 1024);
int n_frames = 0;
double start = gettime();
double start = get_time();
for (int i = 0; i < 100000; i++)
{
n_frames += samples.size() / 2;
vector<float> out_samples = limiter.process (samples);
}
double end = gettime();
double end = get_time();
printf ("%f ns/frame\n", (end - start) * 1000 * 1000 * 1000 / n_frames);
return 0;
}
......
......@@ -18,20 +18,9 @@
#include "utils.hh"
#include "random.hh"
#include <sys/time.h>
using std::vector;
using std::string;
static double
gettime()
{
timeval tv;
gettimeofday (&tv, 0);
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
int
main (int argc, char **argv)
{
......@@ -43,13 +32,13 @@ main (int argc, char **argv)
}
uint64_t s = 0;
double t_start = gettime();
double t_start = get_time();
size_t runs = 25000000;
for (size_t i = 0; i < runs; i++)
{
s += rng();
}
double t_end = gettime();
double t_end = get_time();
printf ("s=%016lx\n\n", s);
printf ("%f Mvalues/sec\n", runs / (t_end - t_start) / 1000000);
......
......@@ -18,9 +18,21 @@
#include "utils.hh"
#include "stdarg.h"
#include <sys/time.h>
using std::vector;
using std::string;
double
get_time()
{
/* return timestamp in seconds as double */
timeval tv;
gettimeofday (&tv, 0);
return tv.tv_sec + tv.tv_usec / 1000000.0;
}
static unsigned char
from_hex_nibble (char c)
{
......
......@@ -27,6 +27,8 @@ std::string bit_vec_to_str (const std::vector<int>& bit_vec);
std::vector<unsigned char> hex_str_to_vec (const std::string& str);
std::string vec_to_hex_str (const std::vector<unsigned char>& vec);
double get_time();
template<typename T>
inline const T&
bound (const T& min_value, const T& value, const T& max_value)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment