Changeset 880
 Timestamp:
 Aug 30, 2011, 1:26:58 AM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test/lolbench.cpp
r879 r880 21 21 using namespace lol; 22 22 23 static size_t const MATRIX_TABLE_SIZE = 64 * 1024; 24 static size_t const MATRIX_RUNS = 100; 25 23 26 static size_t const HALF_TABLE_SIZE = 1024 * 1024; 24 static size_t const HALF_RUNS = 100; 25 27 static size_t const HALF_RUNS = 50; 28 29 static void bench_matrix(int mode); 26 30 static void bench_half(int mode); 27 31 28 32 int main(int argc, char **argv) 29 33 { 34 Log::Info("\n"); 35 Log::Info(" Float matrices [2.0, 2.0]\n"); 36 Log::Info("\n"); 37 bench_matrix(1); 38 39 Log::Info("\n"); 40 Log::Info(" Half precision floats (random bits)\n"); 41 Log::Info("\n"); 42 bench_half(1); 43 30 44 Log::Info("\n"); 31 Log::Info(" Half precision floats (random bits)\n");45 Log::Info(" Half precision floats [2.0, 2.0]\n"); 32 46 Log::Info("\n"); 33 bench_half(1);34 35 Log::Info("\n");36 Log::Info("Half precision floats [2.0, 2.0]\n");37 Log::Info("\n");38 47 bench_half(2); 39 48 … … 41 50 } 42 51 52 static void bench_matrix(int mode) 53 { 54 float result[5] = { 0.0f }; 55 Timer timer; 56 57 /* Set up tables */ 58 mat4 *pm = new mat4[MATRIX_TABLE_SIZE + 1]; 59 float *pf = new float[MATRIX_TABLE_SIZE]; 60 61 for (size_t run = 0; run < MATRIX_RUNS; run++) 62 { 63 switch (mode) 64 { 65 case 1: 66 for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) 67 for (int j = 0; j < 4; j++) 68 for (int k = 0; k < 4; k++) 69 pm[i][j][k] = RandF(2.0f, 2.0f); 70 break; 71 } 72 73 /* Copy matrices */ 74 timer.GetMs(); 75 for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) 76 pm[i] = pm[i + 1]; 77 result[0] += timer.GetMs(); 78 79 /* Determinant */ 80 timer.GetMs(); 81 for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) 82 pf[i] = pm[i].det(); 83 result[1] += timer.GetMs(); 84 85 /* Multiply matrices */ 86 timer.GetMs(); 87 for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) 88 pm[i] *= pm[i + 1]; 89 result[2] += timer.GetMs(); 90 91 /* Add matrices */ 92 timer.GetMs(); 93 for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) 94 pm[i] += pm[i + 1]; 95 result[3] += timer.GetMs(); 96 97 /* Invert matrix */ 98 timer.GetMs(); 99 for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) 100 pm[i] = pm[i].invert(); 101 result[4] += timer.GetMs(); 102 } 103 104 delete[] pm; 105 delete[] pf; 106 107 for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) 108 result[i] *= 1000000.0f / (MATRIX_TABLE_SIZE * MATRIX_RUNS); 109 110 Log::Info(" ns/elem\n"); 111 Log::Info("mat4 = mat4 %7.3f\n", result[0]); 112 Log::Info("float = mat4.det() %7.3f\n", result[1]); 113 Log::Info("mat4 *= mat4 %7.3f\n", result[2]); 114 Log::Info("mat4 += mat4 %7.3f\n", result[3]); 115 Log::Info("mat4 = mat4.invert() %7.3f\n", result[4]); 116 } 117 43 118 static void bench_half(int mode) 44 119 { 45 float result[ 8] = { 0.0f };120 float result[10] = { 0.0f }; 46 121 Timer timer; 47 122 48 123 /* Set up tables */ 49 float *pf = new float[HALF_TABLE_SIZE]; 50 half *ph = new half[HALF_TABLE_SIZE]; 51 52 switch (mode) 53 { 54 case 1: 55 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 56 ph[i] = half::makebits(rand()); 57 break; 58 case 2: 59 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 60 ph[i] = RandF(2.0f, 2.0f); 61 break; 62 } 124 float *pf = new float[HALF_TABLE_SIZE + 1]; 125 half *ph = new half[HALF_TABLE_SIZE + 1]; 63 126 64 127 for (size_t run = 0; run < HALF_RUNS; run++) 65 128 { 129 switch (mode) 130 { 131 case 1: 132 for (size_t i = 0; i < HALF_TABLE_SIZE + 1; i++) 133 ph[i] = half::makebits(rand()); 134 break; 135 case 2: 136 for (size_t i = 0; i < HALF_TABLE_SIZE + 1; i++) 137 ph[i] = RandF(2.0f, 2.0f); 138 break; 139 } 140 #if defined __EXCEPTIONS 141 #error lol 142 #endif 143 144 /* Copy float */ 145 timer.GetMs(); 146 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 147 pf[i] = pf[i + 1]; 148 result[0] += timer.GetMs(); 149 66 150 /* Convert half to float (array) */ 67 151 timer.GetMs(); 68 152 half::convert(pf, ph, HALF_TABLE_SIZE); 69 result[ 0] += timer.GetMs();153 result[1] += timer.GetMs(); 70 154 71 155 /* Convert half to float (fast) */ … … 73 157 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 74 158 pf[i] = (float)ph[i]; 75 result[1] += timer.GetMs();76 77 /* Convert float to half (array) */78 timer.GetMs();79 half::convert(ph, pf, HALF_TABLE_SIZE);80 159 result[2] += timer.GetMs(); 81 160 82 /* Convert float to half (fast)*/83 timer.GetMs(); 84 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 85 p h[i] = (half)pf[i];161 /* Add a half to every float */ 162 timer.GetMs(); 163 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 164 pf[i] += ph[i]; 86 165 result[3] += timer.GetMs(); 87 166 88 /* Co nvert float to half (accurate)*/89 timer.GetMs(); 90 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 91 ph[i] = half::makeaccurate(pf[i]);167 /* Copy half */ 168 timer.GetMs(); 169 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 170 ph[i] = ph[i + 1]; 92 171 result[4] += timer.GetMs(); 93 172 … … 98 177 result[5] += timer.GetMs(); 99 178 100 /* Add a half to every float */ 101 timer.GetMs(); 102 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 103 pf[i] += ph[i]; 179 /* Convert float to half (array) */ 180 timer.GetMs(); 181 half::convert(ph, pf, HALF_TABLE_SIZE); 104 182 result[6] += timer.GetMs(); 105 183 184 /* Convert float to half (fast) */ 185 timer.GetMs(); 186 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 187 ph[i] = (half)pf[i]; 188 result[7] += timer.GetMs(); 189 190 /* Convert float to half (accurate) */ 191 timer.GetMs(); 192 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 193 ph[i] = half::makeaccurate(pf[i]); 194 result[8] += timer.GetMs(); 195 106 196 /* Add a float to every half */ 107 197 timer.GetMs(); 108 198 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 109 199 ph[i] += pf[i]; 110 result[ 7] += timer.GetMs();200 result[9] += timer.GetMs(); 111 201 } 112 202 113 delete[] pf;114 delete[] ph;203 delete[] pf; 204 delete[] ph; 115 205 116 206 for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) … … 118 208 119 209 Log::Info(" ns/elem\n"); 120 Log::Info("float [] = half[]%7.3f\n", result[0]);121 Log::Info("float = half 122 Log::Info(" half[] = float[]%7.3f\n", result[2]);123 Log::Info(" half = float (fast)%7.3f\n", result[3]);124 Log::Info("half = float (accurate)%7.3f\n", result[4]);210 Log::Info("float = float %7.3f\n", result[0]); 211 Log::Info("float = half (array) %7.3f\n", result[1]); 212 Log::Info("float = half (fast) %7.3f\n", result[2]); 213 Log::Info("float += half %7.3f\n", result[3]); 214 Log::Info("half = half %7.3f\n", result[4]); 125 215 Log::Info("half = half %7.3f\n", result[5]); 126 Log::Info("float += half %7.3f\n", result[6]); 127 Log::Info("half += float %7.3f\n", result[7]); 216 Log::Info("half = float (array) %7.3f\n", result[6]); 217 Log::Info("half = float (fast) %7.3f\n", result[7]); 218 Log::Info("half = float (accurate) %7.3f\n", result[8]); 219 Log::Info("half += float %7.3f\n", result[9]); 128 220 } 129 221
Note: See TracChangeset
for help on using the changeset viewer.