Bläddra i källkod

core: new benchmark snippet for operations on reals.

legacy
Sam Hocevar sam 13 år sedan
förälder
incheckning
fde544911b
3 ändrade filer med 77 tillägg och 1 borttagningar
  1. +2
    -1
      test/Makefile.am
  2. +69
    -0
      test/benchmark/real.cpp
  3. +6
    -0
      test/benchsuite.cpp

+ 2
- 1
test/Makefile.am Visa fil

@@ -25,7 +25,8 @@ testsuite_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@
testsuite_DEPENDENCIES = $(top_builddir)/src/liblol.a

benchsuite_SOURCES = benchsuite.cpp \
benchmark/matrix.cpp benchmark/half.cpp benchmark/trig.cpp
benchmark/matrix.cpp benchmark/half.cpp benchmark/trig.cpp \
benchmark/real.cpp
benchsuite_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@
benchsuite_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@
benchsuite_DEPENDENCIES = $(top_builddir)/src/liblol.a


+ 69
- 0
test/benchmark/real.cpp Visa fil

@@ -0,0 +1,69 @@
//
// Lol Engine - Benchmark program
//
// Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://sam.zoy.org/projects/COPYING.WTFPL for more details.
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#include <cstdio>

#include "core.h"

using namespace std;
using namespace lol;

static size_t const REAL_TABLE_SIZE = 10000;
static size_t const REAL_RUNS = 50;

void bench_real(int mode)
{
float result[12] = { 0.0f };
Timer timer;

for (size_t run = 0; run < REAL_RUNS; run++)
{
switch (mode)
{
case 1:
break;
}

real fib1 = 1.0, fib2 = 1.0;
timer.GetMs();
for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
{
real tmp = fib1 + fib2;
fib1 = fib2;
fib2 = tmp;
}
result[0] += timer.GetMs();

real fact = 1.0;
timer.GetMs();
for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
fact = fact * real(1.0 + i);
result[1] += timer.GetMs();

real invfact = 1.0;
timer.GetMs();
for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
invfact = invfact / real(1.0 + i);
result[2] += timer.GetMs();
}

for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
result[i] *= 1000000.0f / (REAL_TABLE_SIZE * REAL_RUNS);

Log::Info(" ns/elem\n");
Log::Info("real = real + real %7.3f\n", result[0]);
Log::Info("real = real * real %7.3f\n", result[1]);
Log::Info("real = real / real %7.3f\n", result[2]);
}


+ 6
- 0
test/benchsuite.cpp Visa fil

@@ -23,12 +23,18 @@
using namespace std;
using namespace lol;

void bench_real(int mode);
void bench_trig(int mode);
void bench_matrix(int mode);
void bench_half(int mode);

int main(int argc, char **argv)
{
Log::Info("-----------------------\n");
Log::Info(" High precision floats\n");
Log::Info("-----------------------\n");
bench_real(1);

Log::Info("--------------------------\n");
Log::Info(" Trigonometry [-1e5, 1e5]\n");
Log::Info("--------------------------\n");


Laddar…
Avbryt
Spara