2
2
// All rights reserved. Use of this source code is governed by a BSD-style
3
3
// license that can be found in the LICENSE file.
4
4
5
+ // ignore_for_file: deprecated_member_use_from_same_package
6
+
5
7
import 'dart:math' as math;
6
8
import 'dart:typed_data' ;
7
9
@@ -321,6 +323,148 @@ class Matrix3TransposeMultiplyBenchmark extends BenchmarkBase {
321
323
}
322
324
}
323
325
326
+ class Matrix4TranslateByDoubleGenericBenchmark extends BenchmarkBase {
327
+ Matrix4TranslateByDoubleGenericBenchmark ()
328
+ : super ('Matrix4.translateByDoubleGeneric' );
329
+
330
+ final temp = Matrix4 .zero ()..setIdentity ();
331
+
332
+ static void main () {
333
+ Matrix4TranslateByDoubleGenericBenchmark ().report ();
334
+ }
335
+
336
+ @override
337
+ void run () {
338
+ for (var i = 0 ; i < 100 ; i++ ) {
339
+ temp.translate (10.0 , 20.0 , 30.0 );
340
+ }
341
+ }
342
+ }
343
+
344
+ class Matrix4TranslateByVector3GenericBenchmark extends BenchmarkBase {
345
+ Matrix4TranslateByVector3GenericBenchmark ()
346
+ : super ('Matrix4.translateByVector3Generic' );
347
+
348
+ final temp = Matrix4 .zero ()..setIdentity ();
349
+ final vec = Vector3 (10.0 , 20.0 , 30.0 );
350
+
351
+ static void main () {
352
+ Matrix4TranslateByVector3GenericBenchmark ().report ();
353
+ }
354
+
355
+ @override
356
+ void run () {
357
+ for (var i = 0 ; i < 100 ; i++ ) {
358
+ temp.translate (vec);
359
+ }
360
+ }
361
+ }
362
+
363
+ class Matrix4TranslateByVector4GenericBenchmark extends BenchmarkBase {
364
+ Matrix4TranslateByVector4GenericBenchmark ()
365
+ : super ('Matrix4.translateByVector4Generic' );
366
+
367
+ final temp = Matrix4 .zero ()..setIdentity ();
368
+ final vec = Vector4 (10.0 , 20.0 , 30.0 , 40.0 );
369
+
370
+ static void main () {
371
+ Matrix4TranslateByVector4GenericBenchmark ().report ();
372
+ }
373
+
374
+ @override
375
+ void run () {
376
+ for (var i = 0 ; i < 100 ; i++ ) {
377
+ temp.translate (vec);
378
+ }
379
+ }
380
+ }
381
+
382
+ class Matrix4TranslateByDoubleBenchmark extends BenchmarkBase {
383
+ Matrix4TranslateByDoubleBenchmark () : super ('Matrix4.translateByDouble' );
384
+
385
+ final temp = Matrix4 .zero ()..setIdentity ();
386
+
387
+ static void main () {
388
+ Matrix4TranslateByDoubleBenchmark ().report ();
389
+ }
390
+
391
+ // Call the benchmarked method with random arguments to make sure TFA won't
392
+ // specialize it based on the arguments passed and wasm-opt won't inline it,
393
+ // for fair comparison with the generic case.
394
+ @override
395
+ void setup () {
396
+ for (var i = 0 ; i < 10 ; i++ ) {
397
+ temp.translateByDouble (
398
+ i.toDouble (), (i * 10 ).toDouble (), (i * 5 ).toDouble (), 1.0 );
399
+ }
400
+ }
401
+
402
+ @override
403
+ void run () {
404
+ for (var i = 0 ; i < 100 ; i++ ) {
405
+ temp.translateByDouble (10.0 , 20.0 , 30.0 , 1.0 );
406
+ }
407
+ }
408
+ }
409
+
410
+ class Matrix4TranslateByVector3Benchmark extends BenchmarkBase {
411
+ Matrix4TranslateByVector3Benchmark () : super ('Matrix4.translateByVector3' );
412
+
413
+ final temp = Matrix4 .zero ()..setIdentity ();
414
+ final vec = Vector3 (10.0 , 20.0 , 30.0 );
415
+
416
+ static void main () {
417
+ Matrix4TranslateByVector3Benchmark ().report ();
418
+ }
419
+
420
+ // Call the benchmarked method with random arguments to make sure TFA won't
421
+ // specialize it based on the arguments passed and wasm-opt won't inline it,
422
+ // for fair comparison with the generic case.
423
+ @override
424
+ void setup () {
425
+ for (var i = 0 ; i < 10 ; i++ ) {
426
+ temp.translateByVector3 (
427
+ Vector3 (i.toDouble (), (i * 10 ).toDouble (), (i * 5 ).toDouble ()));
428
+ }
429
+ }
430
+
431
+ @override
432
+ void run () {
433
+ for (var i = 0 ; i < 100 ; i++ ) {
434
+ temp.translateByVector3 (vec);
435
+ }
436
+ }
437
+ }
438
+
439
+ class Matrix4TranslateByVector4Benchmark extends BenchmarkBase {
440
+ Matrix4TranslateByVector4Benchmark () : super ('Matrix4.translateByVector4' );
441
+
442
+ final temp = Matrix4 .zero ()..setIdentity ();
443
+ final vec = Vector4 (10.0 , 20.0 , 30.0 , 40.0 );
444
+
445
+ static void main () {
446
+ Matrix4TranslateByVector4Benchmark ().report ();
447
+ }
448
+
449
+ // Call the benchmarked method with random arguments to make sure TFA won't
450
+ // specialize it based on the arguments passed and wasm-opt won't inline it,
451
+ // for fair comparison with the generic case.
452
+ @override
453
+ void setup () {
454
+ for (var i = 0 ; i < 10 ; i++ ) {
455
+ temp.translateByVector4 (Vector4 (i.toDouble (), (i * 10 ).toDouble (),
456
+ (i * 5 ).toDouble (), (i * 20 ).toDouble ()));
457
+ }
458
+ }
459
+
460
+ @override
461
+ void run () {
462
+ for (var i = 0 ; i < 100 ; i++ ) {
463
+ temp.translateByVector4 (vec);
464
+ }
465
+ }
466
+ }
467
+
324
468
void main () {
325
469
MatrixMultiplyBenchmark .main ();
326
470
SIMDMatrixMultiplyBenchmark .main ();
@@ -335,4 +479,10 @@ void main() {
335
479
Matrix3TransformVector3Benchmark .main ();
336
480
Matrix3TransformVector2Benchmark .main ();
337
481
Matrix3TransposeMultiplyBenchmark .main ();
482
+ Matrix4TranslateByDoubleGenericBenchmark .main ();
483
+ Matrix4TranslateByVector3GenericBenchmark .main ();
484
+ Matrix4TranslateByVector4GenericBenchmark .main ();
485
+ Matrix4TranslateByDoubleBenchmark .main ();
486
+ Matrix4TranslateByVector3Benchmark .main ();
487
+ Matrix4TranslateByVector4Benchmark .main ();
338
488
}
0 commit comments