From 9be24ce9469fbb13a8e507f0728b23bcf3ae4805 Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Mon, 24 Aug 2020 14:37:28 +0000 Subject: [PATCH] [benchmark] Import MD5/SHA1/SHA256/SkeletalAnimation/SkeletalAnimationSIMD benchmarks from benchmarks-internal Change-Id: I8b7a740091a438babfdd05dd81423b5593d3d7e3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/156020 Commit-Queue: Martin Kustermann Reviewed-by: Jonas Termansen --- benchmarks/MD5/dart/md5.dart | 37 +++++++++++++++++ benchmarks/MD5/dart2/md5.dart | 40 ++++++++++++++++++ benchmarks/SHA1/dart/sha1.dart | 37 +++++++++++++++++ benchmarks/SHA1/dart2/sha1.dart | 40 ++++++++++++++++++ benchmarks/SHA256/dart/sha256.dart | 38 +++++++++++++++++ benchmarks/SHA256/dart2/sha256.dart | 41 +++++++++++++++++++ .../dart/SkeletalAnimation.dart | 33 +++++++++++++++ .../dart2/SkeletalAnimation.dart | 33 +++++++++++++++ .../dart/SkeletalAnimationSIMD.dart | 33 +++++++++++++++ .../dart2/SkeletalAnimationSIMD.dart | 33 +++++++++++++++ 10 files changed, 365 insertions(+) create mode 100644 benchmarks/MD5/dart/md5.dart create mode 100644 benchmarks/MD5/dart2/md5.dart create mode 100644 benchmarks/SHA1/dart/sha1.dart create mode 100644 benchmarks/SHA1/dart2/sha1.dart create mode 100644 benchmarks/SHA256/dart/sha256.dart create mode 100644 benchmarks/SHA256/dart2/sha256.dart create mode 100644 benchmarks/SkeletalAnimation/dart/SkeletalAnimation.dart create mode 100644 benchmarks/SkeletalAnimation/dart2/SkeletalAnimation.dart create mode 100644 benchmarks/SkeletalAnimationSIMD/dart/SkeletalAnimationSIMD.dart create mode 100644 benchmarks/SkeletalAnimationSIMD/dart2/SkeletalAnimationSIMD.dart diff --git a/benchmarks/MD5/dart/md5.dart b/benchmarks/MD5/dart/md5.dart new file mode 100644 index 00000000000..30dd6d435c3 --- /dev/null +++ b/benchmarks/MD5/dart/md5.dart @@ -0,0 +1,37 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:benchmark_harness/benchmark_harness.dart'; +import 'package:convert/convert.dart'; +import 'package:crypto/crypto.dart'; + +const size = 8 * 1024; +const expected = '6556112372898c69e1de0bf689d8db26'; + +class MD5Bench extends BenchmarkBase { + List data; + + MD5Bench() + : data = List.generate(size, (i) => i % 256, growable: false), + super('MD5'); + + @override + void warmup() { + for (int i = 0; i < 4; i++) { + run(); + } + } + + @override + void run() { + final hash = md5.convert(data); + if (hex.encode(hash.bytes) != expected) { + throw 'Incorrect HASH computed.'; + } + } +} + +void main() { + MD5Bench().report(); +} diff --git a/benchmarks/MD5/dart2/md5.dart b/benchmarks/MD5/dart2/md5.dart new file mode 100644 index 00000000000..a65803d3233 --- /dev/null +++ b/benchmarks/MD5/dart2/md5.dart @@ -0,0 +1,40 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:benchmark_harness/benchmark_harness.dart'; +import 'package:convert/convert.dart'; +import 'package:crypto/crypto.dart'; + +const size = 8 * 1024; +const expected = '6556112372898c69e1de0bf689d8db26'; + +class MD5Bench extends BenchmarkBase { + List data; + + MD5Bench() : super('MD5') { + data = List(size); + for (int i = 0; i < data.length; i++) { + data[i] = i % 256; + } + } + + @override + void warmup() { + for (int i = 0; i < 4; i++) { + run(); + } + } + + @override + void run() { + final hash = md5.convert(data); + if (hex.encode(hash.bytes) != expected) { + throw 'Incorrect HASH computed.'; + } + } +} + +void main() { + MD5Bench().report(); +} diff --git a/benchmarks/SHA1/dart/sha1.dart b/benchmarks/SHA1/dart/sha1.dart new file mode 100644 index 00000000000..713cb87e9d9 --- /dev/null +++ b/benchmarks/SHA1/dart/sha1.dart @@ -0,0 +1,37 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:benchmark_harness/benchmark_harness.dart'; +import 'package:convert/convert.dart'; +import 'package:crypto/crypto.dart'; + +const size = 8 * 1024; +const expected = 'ecca46e1a1d0a6012713b09a870d84f695b6d9b0'; + +class SHA1Bench extends BenchmarkBase { + List data; + + SHA1Bench() + : data = List.generate(size, (i) => i % 256, growable: false), + super('SHA1'); + + @override + void warmup() { + for (int i = 0; i < 4; i++) { + run(); + } + } + + @override + void run() { + final hash = sha1.convert(data); + if (hex.encode(hash.bytes) != expected) { + throw 'Incorrect HASH computed.'; + } + } +} + +void main() { + SHA1Bench().report(); +} diff --git a/benchmarks/SHA1/dart2/sha1.dart b/benchmarks/SHA1/dart2/sha1.dart new file mode 100644 index 00000000000..4ce65f5726e --- /dev/null +++ b/benchmarks/SHA1/dart2/sha1.dart @@ -0,0 +1,40 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:benchmark_harness/benchmark_harness.dart'; +import 'package:convert/convert.dart'; +import 'package:crypto/crypto.dart'; + +const size = 8 * 1024; +const expected = 'ecca46e1a1d0a6012713b09a870d84f695b6d9b0'; + +class SHA1Bench extends BenchmarkBase { + List data; + + SHA1Bench() : super('SHA1') { + data = List(size); + for (int i = 0; i < data.length; i++) { + data[i] = i % 256; + } + } + + @override + void warmup() { + for (int i = 0; i < 4; i++) { + run(); + } + } + + @override + void run() { + final hash = sha1.convert(data); + if (hex.encode(hash.bytes) != expected) { + throw 'Incorrect HASH computed.'; + } + } +} + +void main() { + SHA1Bench().report(); +} diff --git a/benchmarks/SHA256/dart/sha256.dart b/benchmarks/SHA256/dart/sha256.dart new file mode 100644 index 00000000000..83ae27d9860 --- /dev/null +++ b/benchmarks/SHA256/dart/sha256.dart @@ -0,0 +1,38 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:benchmark_harness/benchmark_harness.dart'; +import 'package:convert/convert.dart'; +import 'package:crypto/crypto.dart'; + +const size = 8 * 1024; +const expected = + 'dc404a613fedaeb54034514bc6505f56b933caa5250299ba7d094377a51caa46'; + +class SHA256Bench extends BenchmarkBase { + List data; + + SHA256Bench() + : data = List.generate(size, (i) => i % 256, growable: false), + super('SHA256'); + + @override + void warmup() { + for (int i = 0; i < 4; i++) { + run(); + } + } + + @override + void run() { + final hash = sha256.convert(data); + if (hex.encode(hash.bytes) != expected) { + throw 'Incorrect HASH computed.'; + } + } +} + +void main() { + SHA256Bench().report(); +} diff --git a/benchmarks/SHA256/dart2/sha256.dart b/benchmarks/SHA256/dart2/sha256.dart new file mode 100644 index 00000000000..c1383878dff --- /dev/null +++ b/benchmarks/SHA256/dart2/sha256.dart @@ -0,0 +1,41 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:benchmark_harness/benchmark_harness.dart'; +import 'package:convert/convert.dart'; +import 'package:crypto/crypto.dart'; + +const size = 8 * 1024; +const expected = + 'dc404a613fedaeb54034514bc6505f56b933caa5250299ba7d094377a51caa46'; + +class SHA256Bench extends BenchmarkBase { + List data; + + SHA256Bench() : super('SHA256') { + data = List(size); + for (int i = 0; i < data.length; i++) { + data[i] = i % 256; + } + } + + @override + void warmup() { + for (int i = 0; i < 4; i++) { + run(); + } + } + + @override + void run() { + final hash = sha256.convert(data); + if (hex.encode(hash.bytes) != expected) { + throw 'Incorrect HASH computed.'; + } + } +} + +void main() { + SHA256Bench().report(); +} diff --git a/benchmarks/SkeletalAnimation/dart/SkeletalAnimation.dart b/benchmarks/SkeletalAnimation/dart/SkeletalAnimation.dart new file mode 100644 index 00000000000..adda3d3caae --- /dev/null +++ b/benchmarks/SkeletalAnimation/dart/SkeletalAnimation.dart @@ -0,0 +1,33 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// A Dart implementation of two computation kernels used for skeletal +/// animation. + +import 'dart:typed_data'; + +import 'package:benchmark_harness/benchmark_harness.dart'; +import 'package:vector_math/vector_math_operations.dart'; + +void main() { + SkeletalAnimation().report(); +} + +class SkeletalAnimation extends BenchmarkBase { + SkeletalAnimation() : super('SkeletalAnimation'); + + final Float32List A = Float32List(16); + final Float32List B = Float32List(16); + final Float32List C = Float32List(16); + final Float32List D = Float32List(4); + final Float32List E = Float32List(4); + + @override + void run() { + for (int i = 0; i < 100; i++) { + Matrix44Operations.multiply(C, 0, A, 0, B, 0); + Matrix44Operations.transform4(E, 0, A, 0, D, 0); + } + } +} diff --git a/benchmarks/SkeletalAnimation/dart2/SkeletalAnimation.dart b/benchmarks/SkeletalAnimation/dart2/SkeletalAnimation.dart new file mode 100644 index 00000000000..adda3d3caae --- /dev/null +++ b/benchmarks/SkeletalAnimation/dart2/SkeletalAnimation.dart @@ -0,0 +1,33 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// A Dart implementation of two computation kernels used for skeletal +/// animation. + +import 'dart:typed_data'; + +import 'package:benchmark_harness/benchmark_harness.dart'; +import 'package:vector_math/vector_math_operations.dart'; + +void main() { + SkeletalAnimation().report(); +} + +class SkeletalAnimation extends BenchmarkBase { + SkeletalAnimation() : super('SkeletalAnimation'); + + final Float32List A = Float32List(16); + final Float32List B = Float32List(16); + final Float32List C = Float32List(16); + final Float32List D = Float32List(4); + final Float32List E = Float32List(4); + + @override + void run() { + for (int i = 0; i < 100; i++) { + Matrix44Operations.multiply(C, 0, A, 0, B, 0); + Matrix44Operations.transform4(E, 0, A, 0, D, 0); + } + } +} diff --git a/benchmarks/SkeletalAnimationSIMD/dart/SkeletalAnimationSIMD.dart b/benchmarks/SkeletalAnimationSIMD/dart/SkeletalAnimationSIMD.dart new file mode 100644 index 00000000000..fc7727e99e7 --- /dev/null +++ b/benchmarks/SkeletalAnimationSIMD/dart/SkeletalAnimationSIMD.dart @@ -0,0 +1,33 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// A Dart implementation of two computation kernels used for skeletal +/// animation. SIMD version. + +import 'dart:typed_data'; + +import 'package:benchmark_harness/benchmark_harness.dart'; +import 'package:vector_math/vector_math_operations.dart'; + +void main() { + SkeletalAnimationSIMD().report(); +} + +class SkeletalAnimationSIMD extends BenchmarkBase { + SkeletalAnimationSIMD() : super('SkeletalAnimationSIMD'); + + final Float32x4List A = Float32x4List(4); + final Float32x4List B = Float32x4List(4); + final Float32x4List C = Float32x4List(4); + final Float32x4List D = Float32x4List(1); + final Float32x4List E = Float32x4List(1); + + @override + void run() { + for (int i = 0; i < 100; i++) { + Matrix44SIMDOperations.multiply(C, 0, A, 0, B, 0); + Matrix44SIMDOperations.transform4(E, 0, A, 0, D, 0); + } + } +} diff --git a/benchmarks/SkeletalAnimationSIMD/dart2/SkeletalAnimationSIMD.dart b/benchmarks/SkeletalAnimationSIMD/dart2/SkeletalAnimationSIMD.dart new file mode 100644 index 00000000000..fc7727e99e7 --- /dev/null +++ b/benchmarks/SkeletalAnimationSIMD/dart2/SkeletalAnimationSIMD.dart @@ -0,0 +1,33 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// A Dart implementation of two computation kernels used for skeletal +/// animation. SIMD version. + +import 'dart:typed_data'; + +import 'package:benchmark_harness/benchmark_harness.dart'; +import 'package:vector_math/vector_math_operations.dart'; + +void main() { + SkeletalAnimationSIMD().report(); +} + +class SkeletalAnimationSIMD extends BenchmarkBase { + SkeletalAnimationSIMD() : super('SkeletalAnimationSIMD'); + + final Float32x4List A = Float32x4List(4); + final Float32x4List B = Float32x4List(4); + final Float32x4List C = Float32x4List(4); + final Float32x4List D = Float32x4List(1); + final Float32x4List E = Float32x4List(1); + + @override + void run() { + for (int i = 0; i < 100; i++) { + Matrix44SIMDOperations.multiply(C, 0, A, 0, B, 0); + Matrix44SIMDOperations.transform4(E, 0, A, 0, D, 0); + } + } +}