Changeset 886
 Timestamp:
 Sep 1, 2011, 7:39:36 PM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test/lolbench.cpp
r881 r886 15 15 #include <cstdio> 16 16 17 #if defined HAVE_FASTMATH_H 18 # include <fastmath.h> 19 #endif 20 17 21 #include "core.h" 18 22 #include "loldebug.h" … … 21 25 using namespace lol; 22 26 27 static size_t const TRIG_TABLE_SIZE = 128 * 1024; 28 static size_t const TRIG_RUNS = 50; 29 23 30 static size_t const MATRIX_TABLE_SIZE = 64 * 1024; 24 31 static size_t const MATRIX_RUNS = 100; … … 27 34 static size_t const HALF_RUNS = 50; 28 35 36 static void bench_trig(int mode); 29 37 static void bench_matrix(int mode); 30 38 static void bench_half(int mode); … … 32 40 int main(int argc, char **argv) 33 41 { 42 Log::Info("\n"); 43 Log::Info(" Trigonometry [1e5, 1e5]\n"); 44 Log::Info("\n"); 45 bench_trig(1); 46 47 Log::Info("\n"); 48 Log::Info(" Trigonometry [pi, pi]\n"); 49 Log::Info("\n"); 50 bench_trig(2); 51 34 52 Log::Info("\n"); 35 53 Log::Info(" Float matrices [2.0, 2.0]\n"); … … 48 66 49 67 return EXIT_SUCCESS; 68 } 69 70 static void bench_trig(int mode) 71 { 72 float result[5] = { 0.0f }; 73 Timer timer; 74 75 /* Set up tables */ 76 float *pf = new float[TRIG_TABLE_SIZE]; 77 float *pf2 = new float[TRIG_TABLE_SIZE]; 78 79 for (size_t run = 0; run < TRIG_RUNS; run++) 80 { 81 switch (mode) 82 { 83 case 1: 84 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 85 pf[i] = RandF(1e5f, 1e5f); 86 break; 87 case 2: 88 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 89 pf[i] = RandF(M_PI, M_PI); 90 break; 91 } 92 93 /* Sin */ 94 timer.GetMs(); 95 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 96 pf2[i] = __builtin_sinf(pf[i]); 97 result[0] += timer.GetMs(); 98 99 /* Fast sin */ 100 timer.GetMs(); 101 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 102 #if defined HAVE_FASTMATH_H 103 pf2[i] = f_sinf(pf[i]); 104 #else 105 pf2[i] = sinf(pf[i]); 106 #endif 107 result[1] += timer.GetMs(); 108 109 /* Lol sin */ 110 timer.GetMs(); 111 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 112 pf2[i] = lol_sin(pf[i]); 113 result[2] += timer.GetMs(); 114 115 /* Cos */ 116 timer.GetMs(); 117 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 118 pf2[i] = __builtin_cosf(pf[i]); 119 result[3] += timer.GetMs(); 120 121 /* Tan */ 122 timer.GetMs(); 123 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 124 pf2[i] = __builtin_tanf(pf[i]); 125 result[4] += timer.GetMs(); 126 } 127 128 delete[] pf; 129 delete[] pf2; 130 131 for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) 132 result[i] *= 1000000.0f / (TRIG_TABLE_SIZE * TRIG_RUNS); 133 134 Log::Info(" ns/elem\n"); 135 Log::Info("float = sinf(float) %7.3f\n", result[0]); 136 Log::Info("float = fastsinf(float) %7.3f\n", result[1]); 137 Log::Info("float = lol_sinf(float) %7.3f\n", result[2]); 138 Log::Info("float = cosf(float) %7.3f\n", result[3]); 139 Log::Info("float = tanf(float) %7.3f\n", result[4]); 50 140 } 51 141
Note: See TracChangeset
for help on using the changeset viewer.