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 | |
---|
19 | using namespace std; |
---|
20 | using namespace lol; |
---|
21 | |
---|
22 | static size_t const REAL_TABLE_SIZE = 10000; |
---|
23 | static size_t const REAL_RUNS = 50; |
---|
24 | |
---|
25 | void bench_real(int mode) |
---|
26 | { |
---|
27 | float result[12] = { 0.0f }; |
---|
28 | Timer timer; |
---|
29 | |
---|
30 | for (size_t run = 0; run < REAL_RUNS; run++) |
---|
31 | { |
---|
32 | switch (mode) |
---|
33 | { |
---|
34 | case 1: |
---|
35 | break; |
---|
36 | } |
---|
37 | |
---|
38 | real fib1 = 1.0, fib2 = 1.0; |
---|
39 | timer.Get(); |
---|
40 | for (size_t i = 0; i < REAL_TABLE_SIZE; i++) |
---|
41 | { |
---|
42 | real tmp = fib1 + fib2; |
---|
43 | fib1 = fib2; |
---|
44 | fib2 = tmp; |
---|
45 | } |
---|
46 | result[0] += timer.Get(); |
---|
47 | |
---|
48 | real fact = 1.0; |
---|
49 | timer.Get(); |
---|
50 | for (size_t i = 0; i < REAL_TABLE_SIZE; i++) |
---|
51 | fact = fact * real(1.0 + i); |
---|
52 | result[1] += timer.Get(); |
---|
53 | |
---|
54 | real invfact = 1.0; |
---|
55 | timer.Get(); |
---|
56 | for (size_t i = 0; i < REAL_TABLE_SIZE; i++) |
---|
57 | invfact = invfact / real(1.0 + i); |
---|
58 | result[2] += timer.Get(); |
---|
59 | |
---|
60 | timer.Get(); |
---|
61 | for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++) |
---|
62 | sin(real(0.01 * i)); |
---|
63 | result[3] += timer.Get() * 128; |
---|
64 | |
---|
65 | timer.Get(); |
---|
66 | for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++) |
---|
67 | exp((real)(int)(i - REAL_TABLE_SIZE / 256)); |
---|
68 | result[4] += timer.Get() * 128; |
---|
69 | } |
---|
70 | |
---|
71 | for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) |
---|
72 | result[i] *= 1e9f / (REAL_TABLE_SIZE * REAL_RUNS); |
---|
73 | |
---|
74 | Log::Info(" ns/elem\n"); |
---|
75 | Log::Info("real = real + real %7.3f\n", result[0]); |
---|
76 | Log::Info("real = real * real %7.3f\n", result[1]); |
---|
77 | Log::Info("real = real / real %7.3f\n", result[2]); |
---|
78 | Log::Info("real = sin(real) %7.3f\n", result[3]); |
---|
79 | Log::Info("real = exp(real) %7.3f\n", result[4]); |
---|
80 | } |
---|
81 | |
---|