| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
| 9 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
| 10 #include "SkMatrixUtils.h" | 10 #include "SkMatrixUtils.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // having unknown values in our arrays can throw off the timing a lot, perhaps | 87 // having unknown values in our arrays can throw off the timing a lot, perhaps |
| 88 // handling NaN values is a lot slower. Anyway, this guy is just meant to put | 88 // handling NaN values is a lot slower. Anyway, this guy is just meant to put |
| 89 // reasonable values in our arrays. | 89 // reasonable values in our arrays. |
| 90 template <typename T> void init9(T array[9]) { | 90 template <typename T> void init9(T array[9]) { |
| 91 SkRandom rand; | 91 SkRandom rand; |
| 92 for (int i = 0; i < 9; i++) { | 92 for (int i = 0; i < 9; i++) { |
| 93 array[i] = rand.nextSScalar1(); | 93 array[i] = rand.nextSScalar1(); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Test the performance of setConcat() non-perspective case: | |
| 98 // using floating point precision only. | |
| 99 class FloatConcatMatrixBench : public MatrixBench { | |
| 100 public: | |
| 101 FloatConcatMatrixBench() : INHERITED("concat_floatfloat") { | |
| 102 init9(mya); | |
| 103 init9(myb); | |
| 104 init9(myr); | |
| 105 } | |
| 106 protected: | |
| 107 virtual int mulLoopCount() const { return 4; } | |
| 108 | |
| 109 static inline void muladdmul(float a, float b, float c, float d, | |
| 110 float* result) { | |
| 111 *result = a * b + c * d; | |
| 112 } | |
| 113 virtual void performTest() { | |
| 114 const float* a = mya; | |
| 115 const float* b = myb; | |
| 116 float* r = myr; | |
| 117 muladdmul(a[0], b[0], a[1], b[3], &r[0]); | |
| 118 muladdmul(a[0], b[1], a[1], b[4], &r[1]); | |
| 119 muladdmul(a[0], b[2], a[1], b[5], &r[2]); | |
| 120 r[2] += a[2]; | |
| 121 muladdmul(a[3], b[0], a[4], b[3], &r[3]); | |
| 122 muladdmul(a[3], b[1], a[4], b[4], &r[4]); | |
| 123 muladdmul(a[3], b[2], a[4], b[5], &r[5]); | |
| 124 r[5] += a[5]; | |
| 125 r[6] = r[7] = 0.0f; | |
| 126 r[8] = 1.0f; | |
| 127 } | |
| 128 private: | |
| 129 float mya [9]; | |
| 130 float myb [9]; | |
| 131 float myr [9]; | |
| 132 typedef MatrixBench INHERITED; | |
| 133 }; | |
| 134 | |
| 135 static inline float SkDoubleToFloat(double x) { | |
| 136 return static_cast<float>(x); | |
| 137 } | |
| 138 | |
| 139 // Test the performance of setConcat() non-perspective case: | |
| 140 // using floating point precision but casting up to float for | |
| 141 // intermediate results during computations. | |
| 142 class FloatDoubleConcatMatrixBench : public MatrixBench { | |
| 143 public: | |
| 144 FloatDoubleConcatMatrixBench() : INHERITED("concat_floatdouble") { | |
| 145 init9(mya); | |
| 146 init9(myb); | |
| 147 init9(myr); | |
| 148 } | |
| 149 protected: | |
| 150 virtual int mulLoopCount() const { return 4; } | |
| 151 | |
| 152 static inline void muladdmul(float a, float b, float c, float d, | |
| 153 float* result) { | |
| 154 *result = SkDoubleToFloat((double)a * b + (double)c * d); | |
| 155 } | |
| 156 virtual void performTest() { | |
| 157 const float* a = mya; | |
| 158 const float* b = myb; | |
| 159 float* r = myr; | |
| 160 muladdmul(a[0], b[0], a[1], b[3], &r[0]); | |
| 161 muladdmul(a[0], b[1], a[1], b[4], &r[1]); | |
| 162 muladdmul(a[0], b[2], a[1], b[5], &r[2]); | |
| 163 r[2] += a[2]; | |
| 164 muladdmul(a[3], b[0], a[4], b[3], &r[3]); | |
| 165 muladdmul(a[3], b[1], a[4], b[4], &r[4]); | |
| 166 muladdmul(a[3], b[2], a[4], b[5], &r[5]); | |
| 167 r[5] += a[5]; | |
| 168 r[6] = r[7] = 0.0f; | |
| 169 r[8] = 1.0f; | |
| 170 } | |
| 171 private: | |
| 172 float mya [9]; | |
| 173 float myb [9]; | |
| 174 float myr [9]; | |
| 175 typedef MatrixBench INHERITED; | |
| 176 }; | |
| 177 | |
| 178 // Test the performance of setConcat() non-perspective case: | |
| 179 // using double precision only. | |
| 180 class DoubleConcatMatrixBench : public MatrixBench { | |
| 181 public: | |
| 182 DoubleConcatMatrixBench() : INHERITED("concat_double") { | |
| 183 init9(mya); | |
| 184 init9(myb); | |
| 185 init9(myr); | |
| 186 } | |
| 187 protected: | |
| 188 virtual int mulLoopCount() const { return 4; } | |
| 189 | |
| 190 static inline void muladdmul(double a, double b, double c, double d, | |
| 191 double* result) { | |
| 192 *result = a * b + c * d; | |
| 193 } | |
| 194 virtual void performTest() { | |
| 195 const double* a = mya; | |
| 196 const double* b = myb; | |
| 197 double* r = myr; | |
| 198 muladdmul(a[0], b[0], a[1], b[3], &r[0]); | |
| 199 muladdmul(a[0], b[1], a[1], b[4], &r[1]); | |
| 200 muladdmul(a[0], b[2], a[1], b[5], &r[2]); | |
| 201 r[2] += a[2]; | |
| 202 muladdmul(a[3], b[0], a[4], b[3], &r[3]); | |
| 203 muladdmul(a[3], b[1], a[4], b[4], &r[4]); | |
| 204 muladdmul(a[3], b[2], a[4], b[5], &r[5]); | |
| 205 r[5] += a[5]; | |
| 206 r[6] = r[7] = 0.0; | |
| 207 r[8] = 1.0; | |
| 208 } | |
| 209 private: | |
| 210 double mya [9]; | |
| 211 double myb [9]; | |
| 212 double myr [9]; | |
| 213 typedef MatrixBench INHERITED; | |
| 214 }; | |
| 215 | |
| 216 class GetTypeMatrixBench : public MatrixBench { | 97 class GetTypeMatrixBench : public MatrixBench { |
| 217 public: | 98 public: |
| 218 GetTypeMatrixBench() | 99 GetTypeMatrixBench() |
| 219 : INHERITED("gettype") { | 100 : INHERITED("gettype") { |
| 220 fArray[0] = (float) fRnd.nextS(); | 101 fArray[0] = (float) fRnd.nextS(); |
| 221 fArray[1] = (float) fRnd.nextS(); | 102 fArray[1] = (float) fRnd.nextS(); |
| 222 fArray[2] = (float) fRnd.nextS(); | 103 fArray[2] = (float) fRnd.nextS(); |
| 223 fArray[3] = (float) fRnd.nextS(); | 104 fArray[3] = (float) fRnd.nextS(); |
| 224 fArray[4] = (float) fRnd.nextS(); | 105 fArray[4] = (float) fRnd.nextS(); |
| 225 fArray[5] = (float) fRnd.nextS(); | 106 fArray[5] = (float) fRnd.nextS(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 253 fMatrix.dirtyMatrixTypeCache(); | 134 fMatrix.dirtyMatrixTypeCache(); |
| 254 junk ^= (fMatrix.getType()); | 135 junk ^= (fMatrix.getType()); |
| 255 } | 136 } |
| 256 private: | 137 private: |
| 257 SkMatrix fMatrix; | 138 SkMatrix fMatrix; |
| 258 float fArray[9]; | 139 float fArray[9]; |
| 259 SkRandom fRnd; | 140 SkRandom fRnd; |
| 260 typedef MatrixBench INHERITED; | 141 typedef MatrixBench INHERITED; |
| 261 }; | 142 }; |
| 262 | 143 |
| 263 class ScaleTransMixedMatrixBench : public MatrixBench { | |
| 264 public: | |
| 265 ScaleTransMixedMatrixBench() : INHERITED("scaletrans_mixed") { | |
| 266 fMatrix.setAll(fRandom.nextSScalar1(), fRandom.nextSScalar1(), fRandom.n
extSScalar1(), | |
| 267 fRandom.nextSScalar1(), fRandom.nextSScalar1(), fRandom.n
extSScalar1(), | |
| 268 fRandom.nextSScalar1(), fRandom.nextSScalar1(), fRandom.n
extSScalar1()); | |
| 269 int i; | |
| 270 for (i = 0; i < kCount; i++) { | |
| 271 fSrc[i].fX = fRandom.nextSScalar1(); | |
| 272 fSrc[i].fY = fRandom.nextSScalar1(); | |
| 273 fDst[i].fX = fRandom.nextSScalar1(); | |
| 274 fDst[i].fY = fRandom.nextSScalar1(); | |
| 275 } | |
| 276 } | |
| 277 protected: | |
| 278 virtual void performTest() { | |
| 279 SkPoint* dst = fDst; | |
| 280 const SkPoint* src = fSrc; | |
| 281 int count = kCount; | |
| 282 float mx = fMatrix[SkMatrix::kMScaleX]; | |
| 283 float my = fMatrix[SkMatrix::kMScaleY]; | |
| 284 float tx = fMatrix[SkMatrix::kMTransX]; | |
| 285 float ty = fMatrix[SkMatrix::kMTransY]; | |
| 286 do { | |
| 287 dst->fY = SkScalarMulAdd(src->fY, my, ty); | |
| 288 dst->fX = SkScalarMulAdd(src->fX, mx, tx); | |
| 289 src += 1; | |
| 290 dst += 1; | |
| 291 } while (--count); | |
| 292 } | |
| 293 private: | |
| 294 enum { | |
| 295 kCount = 16 | |
| 296 }; | |
| 297 SkMatrix fMatrix; | |
| 298 SkPoint fSrc [kCount]; | |
| 299 SkPoint fDst [kCount]; | |
| 300 SkRandom fRandom; | |
| 301 typedef MatrixBench INHERITED; | |
| 302 }; | |
| 303 | |
| 304 class ScaleTransDoubleMatrixBench : public MatrixBench { | |
| 305 public: | |
| 306 ScaleTransDoubleMatrixBench() : INHERITED("scaletrans_double") { | |
| 307 init9(fMatrix); | |
| 308 int i; | |
| 309 for (i = 0; i < kCount; i++) { | |
| 310 fSrc[i].fX = fRandom.nextSScalar1(); | |
| 311 fSrc[i].fY = fRandom.nextSScalar1(); | |
| 312 fDst[i].fX = fRandom.nextSScalar1(); | |
| 313 fDst[i].fY = fRandom.nextSScalar1(); | |
| 314 } | |
| 315 } | |
| 316 protected: | |
| 317 virtual void performTest() { | |
| 318 SkPoint* dst = fDst; | |
| 319 const SkPoint* src = fSrc; | |
| 320 int count = kCount; | |
| 321 // As doubles, on Z600 Linux systems this is 2.5x as expensive as mixed
mode | |
| 322 float mx = (float) fMatrix[SkMatrix::kMScaleX]; | |
| 323 float my = (float) fMatrix[SkMatrix::kMScaleY]; | |
| 324 float tx = (float) fMatrix[SkMatrix::kMTransX]; | |
| 325 float ty = (float) fMatrix[SkMatrix::kMTransY]; | |
| 326 do { | |
| 327 dst->fY = src->fY * my + ty; | |
| 328 dst->fX = src->fX * mx + tx; | |
| 329 src += 1; | |
| 330 dst += 1; | |
| 331 } while (--count); | |
| 332 } | |
| 333 private: | |
| 334 enum { | |
| 335 kCount = 16 | |
| 336 }; | |
| 337 double fMatrix [9]; | |
| 338 SkPoint fSrc [kCount]; | |
| 339 SkPoint fDst [kCount]; | |
| 340 SkRandom fRandom; | |
| 341 typedef MatrixBench INHERITED; | |
| 342 }; | |
| 343 | |
| 344 class DecomposeMatrixBench : public MatrixBench { | 144 class DecomposeMatrixBench : public MatrixBench { |
| 345 public: | 145 public: |
| 346 DecomposeMatrixBench() : INHERITED("decompose") {} | 146 DecomposeMatrixBench() : INHERITED("decompose") {} |
| 347 | 147 |
| 348 protected: | 148 protected: |
| 349 virtual void onPreDraw() { | 149 virtual void onPreDraw() { |
| 350 for (int i = 0; i < 10; ++i) { | 150 for (int i = 0; i < 10; ++i) { |
| 351 SkScalar rot0 = (fRandom.nextBool()) ? fRandom.nextRangeF(-180, 180)
: 0.0f; | 151 SkScalar rot0 = (fRandom.nextBool()) ? fRandom.nextRangeF(-180, 180)
: 0.0f; |
| 352 SkScalar sx = fRandom.nextRangeF(-3000.f, 3000.f); | 152 SkScalar sx = fRandom.nextRangeF(-3000.f, 3000.f); |
| 353 SkScalar sy = (fRandom.nextBool()) ? fRandom.nextRangeF(-3000.f, 300
0.f) : sx; | 153 SkScalar sy = (fRandom.nextBool()) ? fRandom.nextRangeF(-3000.f, 300
0.f) : sx; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 SkMatrix fMatrix; | 221 SkMatrix fMatrix; |
| 422 int fFlags; | 222 int fFlags; |
| 423 unsigned fIteration; | 223 unsigned fIteration; |
| 424 typedef MatrixBench INHERITED; | 224 typedef MatrixBench INHERITED; |
| 425 }; | 225 }; |
| 426 | 226 |
| 427 /////////////////////////////////////////////////////////////////////////////// | 227 /////////////////////////////////////////////////////////////////////////////// |
| 428 | 228 |
| 429 DEF_BENCH( return new EqualsMatrixBench(); ) | 229 DEF_BENCH( return new EqualsMatrixBench(); ) |
| 430 DEF_BENCH( return new ScaleMatrixBench(); ) | 230 DEF_BENCH( return new ScaleMatrixBench(); ) |
| 431 DEF_BENCH( return new FloatConcatMatrixBench(); ) | |
| 432 DEF_BENCH( return new FloatDoubleConcatMatrixBench(); ) | |
| 433 DEF_BENCH( return new DoubleConcatMatrixBench(); ) | |
| 434 DEF_BENCH( return new GetTypeMatrixBench(); ) | 231 DEF_BENCH( return new GetTypeMatrixBench(); ) |
| 435 DEF_BENCH( return new DecomposeMatrixBench(); ) | 232 DEF_BENCH( return new DecomposeMatrixBench(); ) |
| 436 | 233 |
| 437 DEF_BENCH( return new InvertMapRectMatrixBench("invert_maprect_identity", 0); ) | 234 DEF_BENCH( return new InvertMapRectMatrixBench("invert_maprect_identity", 0); ) |
| 438 | 235 |
| 439 DEF_BENCH(return new InvertMapRectMatrixBench( | 236 DEF_BENCH(return new InvertMapRectMatrixBench( |
| 440 "invert_maprect_rectstaysrect", | 237 "invert_maprect_rectstaysrect", |
| 441 InvertMapRectMatrixBench::kScale_Flag | | 238 InvertMapRectMatrixBench::kScale_Flag | |
| 442 InvertMapRectMatrixBench::kTranslate_Flag); ) | 239 InvertMapRectMatrixBench::kTranslate_Flag); ) |
| 443 | 240 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 461 InvertMapRectMatrixBench::kScale_Flag | | 258 InvertMapRectMatrixBench::kScale_Flag | |
| 462 InvertMapRectMatrixBench::kTranslate_Flag); ) | 259 InvertMapRectMatrixBench::kTranslate_Flag); ) |
| 463 | 260 |
| 464 DEF_BENCH( return new InvertMapRectMatrixBench( | 261 DEF_BENCH( return new InvertMapRectMatrixBench( |
| 465 "invert_maprect_typemask_nonpersp", | 262 "invert_maprect_typemask_nonpersp", |
| 466 InvertMapRectMatrixBench::kUncachedTypeMask_Flag | | 263 InvertMapRectMatrixBench::kUncachedTypeMask_Flag | |
| 467 InvertMapRectMatrixBench::kScale_Flag | | 264 InvertMapRectMatrixBench::kScale_Flag | |
| 468 InvertMapRectMatrixBench::kRotate_Flag | | 265 InvertMapRectMatrixBench::kRotate_Flag | |
| 469 InvertMapRectMatrixBench::kTranslate_Flag); ) | 266 InvertMapRectMatrixBench::kTranslate_Flag); ) |
| 470 | 267 |
| 471 DEF_BENCH( return new ScaleTransMixedMatrixBench(); ) | 268 /////////////////////////////////////////////////////////////////////////////// |
| 472 DEF_BENCH( return new ScaleTransDoubleMatrixBench(); ) | 269 |
| 270 static SkMatrix make_ident() { SkMatrix m; m.reset(); return m; } |
| 271 static SkMatrix make_trans() { SkMatrix m; m.setTranslate(2, 3); return m; } |
| 272 static SkMatrix make_scale() { SkMatrix m(make_trans()); m.postScale(1.5f, 0.5f)
; return m; } |
| 273 static SkMatrix make_afine() { SkMatrix m(make_trans()); m.postRotate(15); retur
n m; } |
| 274 |
| 275 class MapPointsMatrixBench : public MatrixBench { |
| 276 protected: |
| 277 SkMatrix fM; |
| 278 enum { |
| 279 N = 32 |
| 280 }; |
| 281 SkPoint fSrc[N], fDst[N]; |
| 282 const bool fNewWay; |
| 283 public: |
| 284 MapPointsMatrixBench(const char name[], const SkMatrix& m, bool newWay) |
| 285 : MatrixBench(name), fM(m), fNewWay(newWay) |
| 286 { |
| 287 SkRandom rand; |
| 288 for (int i = 0; i < N; ++i) { |
| 289 fSrc[i].set(rand.nextSScalar1(), rand.nextSScalar1()); |
| 290 } |
| 291 } |
| 292 |
| 293 void performTest() SK_OVERRIDE { |
| 294 if (fNewWay) { |
| 295 for (int i = 0; i < 1000000; ++i) { |
| 296 fM.mapPts(fDst, fSrc, N); |
| 297 } |
| 298 } else { |
| 299 for (int i = 0; i < 1000000; ++i) { |
| 300 fM.mapPoints(fDst, fSrc, N); |
| 301 } |
| 302 } |
| 303 } |
| 304 }; |
| 305 DEF_BENCH( return new MapPointsMatrixBench("mappts_ident0", make_ident(), false)
; ) |
| 306 DEF_BENCH( return new MapPointsMatrixBench("mappts_ident1", make_ident(), true);
) |
| 307 DEF_BENCH( return new MapPointsMatrixBench("mappts_trans0", make_trans(), false)
; ) |
| 308 DEF_BENCH( return new MapPointsMatrixBench("mappts_trans1", make_trans(), true);
) |
| 309 DEF_BENCH( return new MapPointsMatrixBench("mappts_scale0", make_scale(), false)
; ) |
| 310 DEF_BENCH( return new MapPointsMatrixBench("mappts_scale1", make_scale(), true);
) |
| 311 DEF_BENCH( return new MapPointsMatrixBench("mappts_afine0", make_afine(), false)
; ) |
| 312 DEF_BENCH( return new MapPointsMatrixBench("mappts_afine1", make_afine(), true);
) |
| 313 |
| OLD | NEW |