source: trunk/test/benchmark/vector.cpp @ 1309

Last change on this file since 1309 was 1309, checked in by sam, 8 years ago

core: make timers second-based rather than millisecond-based.

  • Property svn:keywords set to Id
File size: 2.5 KB
RevLine 
[942]1//
2// Lol Engine - Benchmark program
3//
4// Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstdio>
16
17#include "core.h"
18
19using namespace std;
20using namespace lol;
21
22static size_t const MATRIX_TABLE_SIZE = 64 * 1024;
23static size_t const MATRIX_RUNS = 100;
24
25void bench_matrix(int mode)
26{
27    float result[5] = { 0.0f };
28    Timer timer;
29
30    /* Set up tables */
31    mat4 *pm = new mat4[MATRIX_TABLE_SIZE + 1];
32    float *pf = new float[MATRIX_TABLE_SIZE];
33
34    for (size_t run = 0; run < MATRIX_RUNS; run++)
35    {
36        switch (mode)
37        {
38        case 1:
39            for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
40                for (int j = 0; j < 4; j++)
41                    for (int k = 0; k < 4; k++)
42                        pm[i][j][k] = RandF(-2.0f, 2.0f);
43            break;
44        }
45
46        /* Copy matrices */
[1309]47        timer.Get();
[942]48        for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
49            pm[i] = pm[i + 1];
[1309]50        result[0] += timer.Get();
[942]51
52        /* Determinant */
[1309]53        timer.Get();
[942]54        for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
[1257]55            pf[i] = determinant(pm[i]);
[1309]56        result[1] += timer.Get();
[942]57
58        /* Multiply matrices */
[1309]59        timer.Get();
[942]60        for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
61            pm[i] *= pm[i + 1];
[1309]62        result[2] += timer.Get();
[942]63
64        /* Add matrices */
[1309]65        timer.Get();
[942]66        for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
67            pm[i] += pm[i + 1];
[1309]68        result[3] += timer.Get();
[942]69
70        /* Invert matrix */
[1309]71        timer.Get();
[942]72        for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
[1257]73            pm[i] = inverse(pm[i]);
[1309]74        result[4] += timer.Get();
[942]75    }
76
77    delete[] pm;
78    delete[] pf;
79
80    for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
[1309]81        result[i] *= 1e9f / (MATRIX_TABLE_SIZE * MATRIX_RUNS);
[942]82
83    Log::Info("                          ns/elem\n");
84    Log::Info("mat4 = mat4              %7.3f\n", result[0]);
85    Log::Info("float = mat4.det()       %7.3f\n", result[1]);
86    Log::Info("mat4 *= mat4             %7.3f\n", result[2]);
87    Log::Info("mat4 += mat4             %7.3f\n", result[3]);
88    Log::Info("mat4 = mat4.invert()     %7.3f\n", result[4]);
89}
90
Note: See TracBrowser for help on using the repository browser.