mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 15:57:17 +00:00
[ffi/benchmark] Dedup. test code in FfiCall.
This also serves as a step in the refactoring needed for the FFI leaf call benchmark changes in: https://dart-review.googlesource.com/c/sdk/+/179768 Change-Id: I0876d610b1d79b05c4bcd7e3cd9ef48d1beff432 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/186294 Auto-Submit: Clement Skau <cskau@google.com> Commit-Queue: Clement Skau <cskau@google.com> Reviewed-by: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
parent
e7fdd7b693
commit
3e7d590a30
|
@ -15,6 +15,9 @@ import 'package:benchmark_harness/benchmark_harness.dart';
|
||||||
|
|
||||||
import 'dlopen_helper.dart';
|
import 'dlopen_helper.dart';
|
||||||
|
|
||||||
|
// Number of benchmark iterations per function.
|
||||||
|
const N = 1000;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Trampoline functions.
|
// Trampoline functions.
|
||||||
//
|
//
|
||||||
|
@ -725,256 +728,230 @@ Object doCall20Handle(
|
||||||
// Benchmark fixtures.
|
// Benchmark fixtures.
|
||||||
//
|
//
|
||||||
|
|
||||||
// Number of repeats: 1000
|
abstract class FfiBenchmarkBase extends BenchmarkBase {
|
||||||
// * CPU: Intel(R) Xeon(R) Gold 6154
|
FfiBenchmarkBase(String name) : super(name);
|
||||||
// * Architecture: x64
|
|
||||||
// * 200 - 1100 us
|
|
||||||
const N = 1000;
|
|
||||||
|
|
||||||
class Uint8x01 extends BenchmarkBase {
|
void expectEquals(actual, expected) {
|
||||||
|
if (actual != expected) {
|
||||||
|
throw Exception('$name: Unexpected result: $actual, expected $expected');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void expectApprox(actual, expected) {
|
||||||
|
if (0.999 * expected > actual || actual > 1.001 * expected) {
|
||||||
|
throw Exception('$name: Unexpected result: $actual, expected $expected');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void expectIdentical(actual, expected) {
|
||||||
|
if (!identical(actual, expected)) {
|
||||||
|
throw Exception('$name: Unexpected result: $actual, expected $expected');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Uint8x01 extends FfiBenchmarkBase {
|
||||||
Uint8x01() : super('FfiCall.Uint8x01');
|
Uint8x01() : super('FfiCall.Uint8x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Uint8(N);
|
final int x = doCall1Uint8(N);
|
||||||
if (x != N * 17 + N * 42) {
|
expectEquals(x, N * (17 + 42));
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Uint16x01 extends BenchmarkBase {
|
class Uint16x01 extends FfiBenchmarkBase {
|
||||||
Uint16x01() : super('FfiCall.Uint16x01');
|
Uint16x01() : super('FfiCall.Uint16x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Uint16(N);
|
final int x = doCall1Uint16(N);
|
||||||
if (x != N * 17 + N * 42) {
|
expectEquals(x, N * (17 + 42));
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Uint32x01 extends BenchmarkBase {
|
class Uint32x01 extends FfiBenchmarkBase {
|
||||||
Uint32x01() : super('FfiCall.Uint32x01');
|
Uint32x01() : super('FfiCall.Uint32x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Uint32(N);
|
final int x = doCall1Uint32(N);
|
||||||
if (x != N * (N - 1) / 2 + N * 42) {
|
expectEquals(x, N * (N - 1) / 2 + N * 42);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Uint64x01 extends BenchmarkBase {
|
class Uint64x01 extends FfiBenchmarkBase {
|
||||||
Uint64x01() : super('FfiCall.Uint64x01');
|
Uint64x01() : super('FfiCall.Uint64x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Uint64(N);
|
final int x = doCall1Uint64(N);
|
||||||
if (x != N * (N - 1) / 2 + N * 42) {
|
expectEquals(x, N * (N - 1) / 2 + N * 42);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int8x01 extends BenchmarkBase {
|
class Int8x01 extends FfiBenchmarkBase {
|
||||||
Int8x01() : super('FfiCall.Int8x01');
|
Int8x01() : super('FfiCall.Int8x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Int8(N);
|
final int x = doCall1Int8(N);
|
||||||
if (x != N * 17 + N * 42) {
|
expectEquals(x, N * (17 + 42));
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int16x01 extends BenchmarkBase {
|
class Int16x01 extends FfiBenchmarkBase {
|
||||||
Int16x01() : super('FfiCall.Int16x01');
|
Int16x01() : super('FfiCall.Int16x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Int16(N);
|
final int x = doCall1Int16(N);
|
||||||
if (x != N * 17 + N * 42) {
|
expectEquals(x, N * (17 + 42));
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int32x01 extends BenchmarkBase {
|
class Int32x01 extends FfiBenchmarkBase {
|
||||||
Int32x01() : super('FfiCall.Int32x01');
|
Int32x01() : super('FfiCall.Int32x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Int32(N);
|
final int x = doCall1Int32(N);
|
||||||
if (x != N * (N - 1) / 2 + N * 42) {
|
expectEquals(x, N * (N - 1) / 2 + N * 42);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int32x02 extends BenchmarkBase {
|
class Int32x02 extends FfiBenchmarkBase {
|
||||||
Int32x02() : super('FfiCall.Int32x02');
|
Int32x02() : super('FfiCall.Int32x02');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall2Int32(N);
|
final int x = doCall2Int32(N);
|
||||||
if (x != N * (N - 1) * 2 / 2) {
|
expectEquals(x, N * (N - 1) * 2 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int32x04 extends BenchmarkBase {
|
class Int32x04 extends FfiBenchmarkBase {
|
||||||
Int32x04() : super('FfiCall.Int32x04');
|
Int32x04() : super('FfiCall.Int32x04');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall4Int32(N);
|
final int x = doCall4Int32(N);
|
||||||
if (x != N * (N - 1) * 4 / 2) {
|
expectEquals(x, N * (N - 1) * 4 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int32x10 extends BenchmarkBase {
|
class Int32x10 extends FfiBenchmarkBase {
|
||||||
Int32x10() : super('FfiCall.Int32x10');
|
Int32x10() : super('FfiCall.Int32x10');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall10Int32(N);
|
final int x = doCall10Int32(N);
|
||||||
if (x != N * (N - 1) * 10 / 2) {
|
expectEquals(x, N * (N - 1) * 10 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int32x20 extends BenchmarkBase {
|
class Int32x20 extends FfiBenchmarkBase {
|
||||||
Int32x20() : super('FfiCall.Int32x20');
|
Int32x20() : super('FfiCall.Int32x20');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall20Int32(N);
|
final int x = doCall20Int32(N);
|
||||||
if (x != N * (N - 1) * 20 / 2) {
|
expectEquals(x, N * (N - 1) * 20 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int64x01 extends BenchmarkBase {
|
class Int64x01 extends FfiBenchmarkBase {
|
||||||
Int64x01() : super('FfiCall.Int64x01');
|
Int64x01() : super('FfiCall.Int64x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Int64(N);
|
final int x = doCall1Int64(N);
|
||||||
if (x != N * (N - 1) / 2 + N * 42) {
|
expectEquals(x, N * (N - 1) / 2 + N * 42);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int64x02 extends BenchmarkBase {
|
class Int64x02 extends FfiBenchmarkBase {
|
||||||
Int64x02() : super('FfiCall.Int64x02');
|
Int64x02() : super('FfiCall.Int64x02');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall2Int64(N);
|
final int x = doCall2Int64(N);
|
||||||
if (x != N * (N - 1) * 2 / 2) {
|
expectEquals(x, N * (N - 1) * 2 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int64x04 extends BenchmarkBase {
|
class Int64x04 extends FfiBenchmarkBase {
|
||||||
Int64x04() : super('FfiCall.Int64x04');
|
Int64x04() : super('FfiCall.Int64x04');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall4Int64(N);
|
final int x = doCall4Int64(N);
|
||||||
if (x != N * (N - 1) * 4 / 2) {
|
expectEquals(x, N * (N - 1) * 4 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int64x10 extends BenchmarkBase {
|
class Int64x10 extends FfiBenchmarkBase {
|
||||||
Int64x10() : super('FfiCall.Int64x10');
|
Int64x10() : super('FfiCall.Int64x10');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall10Int64(N);
|
final int x = doCall10Int64(N);
|
||||||
if (x != N * (N - 1) * 10 / 2) {
|
expectEquals(x, N * (N - 1) * 10 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int64x20 extends BenchmarkBase {
|
class Int64x20 extends FfiBenchmarkBase {
|
||||||
Int64x20() : super('FfiCall.Int64x20');
|
Int64x20() : super('FfiCall.Int64x20');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall20Int64(N);
|
final int x = doCall20Int64(N);
|
||||||
if (x != N * (N - 1) * 20 / 2) {
|
expectEquals(x, N * (N - 1) * 20 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int64Mintx01 extends BenchmarkBase {
|
class Int64Mintx01 extends FfiBenchmarkBase {
|
||||||
Int64Mintx01() : super('FfiCall.Int64Mintx01');
|
Int64Mintx01() : super('FfiCall.Int64Mintx01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Int64Mint(N);
|
final int x = doCall1Int64Mint(N);
|
||||||
if (x != 0x7FFFFFFF00000000 + N * 42) {
|
expectEquals(x, 0x7FFFFFFF00000000 + N * 42);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Floatx01 extends BenchmarkBase {
|
class Floatx01 extends FfiBenchmarkBase {
|
||||||
Floatx01() : super('FfiCall.Floatx01');
|
Floatx01() : super('FfiCall.Floatx01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final double x = doCall1Float(N);
|
final double x = doCall1Float(N);
|
||||||
final double expected = N * (17.0 + 42);
|
expectApprox(x, N * (17.0 + 42.0));
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Floatx02 extends BenchmarkBase {
|
class Floatx02 extends FfiBenchmarkBase {
|
||||||
Floatx02() : super('FfiCall.Floatx02');
|
Floatx02() : super('FfiCall.Floatx02');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final double x = doCall2Float(N);
|
final double x = doCall2Float(N);
|
||||||
final double expected = N * (1.0 + 2.0);
|
expectApprox(x, N * (1.0 + 2.0));
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Floatx04 extends BenchmarkBase {
|
class Floatx04 extends FfiBenchmarkBase {
|
||||||
Floatx04() : super('FfiCall.Floatx04');
|
Floatx04() : super('FfiCall.Floatx04');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final double x = doCall4Float(N);
|
final double x = doCall4Float(N);
|
||||||
final double expected = N * (1.0 + 2.0 + 3.0 + 4.0);
|
final double expected = N * (1.0 + 2.0 + 3.0 + 4.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Floatx10 extends BenchmarkBase {
|
class Floatx10 extends FfiBenchmarkBase {
|
||||||
Floatx10() : super('FfiCall.Floatx10');
|
Floatx10() : super('FfiCall.Floatx10');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -982,13 +959,11 @@ class Floatx10 extends BenchmarkBase {
|
||||||
final double x = doCall10Float(N);
|
final double x = doCall10Float(N);
|
||||||
final double expected =
|
final double expected =
|
||||||
N * (1.0 + 2.0 + 3.0 + 4.0 + 5.0 + 6.0 + 7.0 + 8.0 + 9.0 + 10.0);
|
N * (1.0 + 2.0 + 3.0 + 4.0 + 5.0 + 6.0 + 7.0 + 8.0 + 9.0 + 10.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Floatx20 extends BenchmarkBase {
|
class Floatx20 extends FfiBenchmarkBase {
|
||||||
Floatx20() : super('FfiCall.Floatx20');
|
Floatx20() : super('FfiCall.Floatx20');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1015,52 +990,44 @@ class Floatx20 extends BenchmarkBase {
|
||||||
18.0 +
|
18.0 +
|
||||||
19.0 +
|
19.0 +
|
||||||
20.0);
|
20.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Doublex01 extends BenchmarkBase {
|
class Doublex01 extends FfiBenchmarkBase {
|
||||||
Doublex01() : super('FfiCall.Doublex01');
|
Doublex01() : super('FfiCall.Doublex01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final double x = doCall1Double(N);
|
final double x = doCall1Double(N);
|
||||||
final double expected = N * (17.0 + 42.0);
|
final double expected = N * (17.0 + 42.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Doublex02 extends BenchmarkBase {
|
class Doublex02 extends FfiBenchmarkBase {
|
||||||
Doublex02() : super('FfiCall.Doublex02');
|
Doublex02() : super('FfiCall.Doublex02');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final double x = doCall2Double(N);
|
final double x = doCall2Double(N);
|
||||||
final double expected = N * (1.0 + 2.0);
|
final double expected = N * (1.0 + 2.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Doublex04 extends BenchmarkBase {
|
class Doublex04 extends FfiBenchmarkBase {
|
||||||
Doublex04() : super('FfiCall.Doublex04');
|
Doublex04() : super('FfiCall.Doublex04');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final double x = doCall4Double(N);
|
final double x = doCall4Double(N);
|
||||||
final double expected = N * (1.0 + 2.0 + 3.0 + 4.0);
|
final double expected = N * (1.0 + 2.0 + 3.0 + 4.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Doublex10 extends BenchmarkBase {
|
class Doublex10 extends FfiBenchmarkBase {
|
||||||
Doublex10() : super('FfiCall.Doublex10');
|
Doublex10() : super('FfiCall.Doublex10');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1068,13 +1035,11 @@ class Doublex10 extends BenchmarkBase {
|
||||||
final double x = doCall10Double(N);
|
final double x = doCall10Double(N);
|
||||||
final double expected =
|
final double expected =
|
||||||
N * (1.0 + 2.0 + 3.0 + 4.0 + 5.0 + 6.0 + 7.0 + 8.0 + 9.0 + 10.0);
|
N * (1.0 + 2.0 + 3.0 + 4.0 + 5.0 + 6.0 + 7.0 + 8.0 + 9.0 + 10.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Doublex20 extends BenchmarkBase {
|
class Doublex20 extends FfiBenchmarkBase {
|
||||||
Doublex20() : super('FfiCall.Doublex20');
|
Doublex20() : super('FfiCall.Doublex20');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1101,13 +1066,11 @@ class Doublex20 extends BenchmarkBase {
|
||||||
18.0 +
|
18.0 +
|
||||||
19.0 +
|
19.0 +
|
||||||
20.0);
|
20.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PointerUint8x01 extends BenchmarkBase {
|
class PointerUint8x01 extends FfiBenchmarkBase {
|
||||||
PointerUint8x01() : super('FfiCall.PointerUint8x01');
|
PointerUint8x01() : super('FfiCall.PointerUint8x01');
|
||||||
|
|
||||||
Pointer<Uint8> pointer = nullptr;
|
Pointer<Uint8> pointer = nullptr;
|
||||||
|
@ -1119,13 +1082,11 @@ class PointerUint8x01 extends BenchmarkBase {
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final Pointer<Uint8> x = doCall1PointerUint8(N, pointer);
|
final Pointer<Uint8> x = doCall1PointerUint8(N, pointer);
|
||||||
if (x.address != pointer.address + N) {
|
expectApprox(x.address, pointer.address + N);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PointerUint8x02 extends BenchmarkBase {
|
class PointerUint8x02 extends FfiBenchmarkBase {
|
||||||
PointerUint8x02() : super('FfiCall.PointerUint8x02');
|
PointerUint8x02() : super('FfiCall.PointerUint8x02');
|
||||||
|
|
||||||
Pointer<Uint8> pointer = nullptr;
|
Pointer<Uint8> pointer = nullptr;
|
||||||
|
@ -1145,13 +1106,11 @@ class PointerUint8x02 extends BenchmarkBase {
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final Pointer<Uint8> x = doCall2PointerUint8(N, pointer, pointer2);
|
final Pointer<Uint8> x = doCall2PointerUint8(N, pointer, pointer2);
|
||||||
if (x.address != pointer.address + N * sizeOf<Uint8>()) {
|
expectEquals(x.address, pointer.address + N * sizeOf<Uint8>());
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PointerUint8x04 extends BenchmarkBase {
|
class PointerUint8x04 extends FfiBenchmarkBase {
|
||||||
PointerUint8x04() : super('FfiCall.PointerUint8x04');
|
PointerUint8x04() : super('FfiCall.PointerUint8x04');
|
||||||
|
|
||||||
Pointer<Uint8> pointer = nullptr;
|
Pointer<Uint8> pointer = nullptr;
|
||||||
|
@ -1176,13 +1135,11 @@ class PointerUint8x04 extends BenchmarkBase {
|
||||||
void run() {
|
void run() {
|
||||||
final Pointer<Uint8> x =
|
final Pointer<Uint8> x =
|
||||||
doCall4PointerUint8(N, pointer, pointer2, pointer3, pointer4);
|
doCall4PointerUint8(N, pointer, pointer2, pointer3, pointer4);
|
||||||
if (x.address != pointer.address + N * sizeOf<Uint8>()) {
|
expectEquals(x.address, pointer.address + N * sizeOf<Uint8>());
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PointerUint8x10 extends BenchmarkBase {
|
class PointerUint8x10 extends FfiBenchmarkBase {
|
||||||
PointerUint8x10() : super('FfiCall.PointerUint8x10');
|
PointerUint8x10() : super('FfiCall.PointerUint8x10');
|
||||||
|
|
||||||
Pointer<Uint8> pointer = nullptr;
|
Pointer<Uint8> pointer = nullptr;
|
||||||
|
@ -1229,13 +1186,11 @@ class PointerUint8x10 extends BenchmarkBase {
|
||||||
pointer8,
|
pointer8,
|
||||||
pointer9,
|
pointer9,
|
||||||
pointer10);
|
pointer10);
|
||||||
if (x.address != pointer.address + N * sizeOf<Uint8>()) {
|
expectEquals(x.address, pointer.address + N * sizeOf<Uint8>());
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PointerUint8x20 extends BenchmarkBase {
|
class PointerUint8x20 extends FfiBenchmarkBase {
|
||||||
PointerUint8x20() : super('FfiCall.PointerUint8x20');
|
PointerUint8x20() : super('FfiCall.PointerUint8x20');
|
||||||
|
|
||||||
Pointer<Uint8> pointer = nullptr;
|
Pointer<Uint8> pointer = nullptr;
|
||||||
|
@ -1312,9 +1267,7 @@ class PointerUint8x20 extends BenchmarkBase {
|
||||||
pointer18,
|
pointer18,
|
||||||
pointer19,
|
pointer19,
|
||||||
pointer20);
|
pointer20);
|
||||||
if (x.address != pointer.address + N * sizeOf<Uint8>()) {
|
expectEquals(x.address, pointer.address + N * sizeOf<Uint8>());
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1323,7 +1276,7 @@ class MyClass {
|
||||||
MyClass(this.a);
|
MyClass(this.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Handlex01 extends BenchmarkBase {
|
class Handlex01 extends FfiBenchmarkBase {
|
||||||
Handlex01() : super('FfiCall.Handlex01');
|
Handlex01() : super('FfiCall.Handlex01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1331,13 +1284,11 @@ class Handlex01 extends BenchmarkBase {
|
||||||
final p1 = MyClass(123);
|
final p1 = MyClass(123);
|
||||||
final x = doCall1Handle(N, p1);
|
final x = doCall1Handle(N, p1);
|
||||||
|
|
||||||
if (!identical(p1, x)) {
|
expectIdentical(x, p1);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Handlex02 extends BenchmarkBase {
|
class Handlex02 extends FfiBenchmarkBase {
|
||||||
Handlex02() : super('FfiCall.Handlex02');
|
Handlex02() : super('FfiCall.Handlex02');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1346,13 +1297,11 @@ class Handlex02 extends BenchmarkBase {
|
||||||
final p2 = MyClass(2);
|
final p2 = MyClass(2);
|
||||||
final x = doCall2Handle(N, p1, p2);
|
final x = doCall2Handle(N, p1, p2);
|
||||||
|
|
||||||
if (!identical(p1, x)) {
|
expectIdentical(x, p1);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Handlex04 extends BenchmarkBase {
|
class Handlex04 extends FfiBenchmarkBase {
|
||||||
Handlex04() : super('FfiCall.Handlex04');
|
Handlex04() : super('FfiCall.Handlex04');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1363,13 +1312,11 @@ class Handlex04 extends BenchmarkBase {
|
||||||
final p4 = MyClass(4);
|
final p4 = MyClass(4);
|
||||||
final x = doCall4Handle(N, p1, p2, p3, p4);
|
final x = doCall4Handle(N, p1, p2, p3, p4);
|
||||||
|
|
||||||
if (!identical(p1, x)) {
|
expectIdentical(x, p1);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Handlex10 extends BenchmarkBase {
|
class Handlex10 extends FfiBenchmarkBase {
|
||||||
Handlex10() : super('FfiCall.Handlex10');
|
Handlex10() : super('FfiCall.Handlex10');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1386,13 +1333,11 @@ class Handlex10 extends BenchmarkBase {
|
||||||
final p10 = MyClass(10);
|
final p10 = MyClass(10);
|
||||||
final x = doCall10Handle(N, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
final x = doCall10Handle(N, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
||||||
|
|
||||||
if (!identical(p1, x)) {
|
expectIdentical(x, p1);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Handlex20 extends BenchmarkBase {
|
class Handlex20 extends FfiBenchmarkBase {
|
||||||
Handlex20() : super('FfiCall.Handlex20');
|
Handlex20() : super('FfiCall.Handlex20');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1420,9 +1365,7 @@ class Handlex20 extends BenchmarkBase {
|
||||||
final x = doCall20Handle(N, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11,
|
final x = doCall20Handle(N, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11,
|
||||||
p12, p13, p14, p15, p16, p17, p18, p19, p20);
|
p12, p13, p14, p15, p16, p17, p18, p19, p20);
|
||||||
|
|
||||||
if (!identical(p1, x)) {
|
expectIdentical(p1, x);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@ import 'package:benchmark_harness/benchmark_harness.dart';
|
||||||
|
|
||||||
import 'dlopen_helper.dart';
|
import 'dlopen_helper.dart';
|
||||||
|
|
||||||
|
// Number of benchmark iterations per function.
|
||||||
|
const N = 1000;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Trampoline functions.
|
// Trampoline functions.
|
||||||
//
|
//
|
||||||
|
@ -727,256 +730,230 @@ Object doCall20Handle(
|
||||||
// Benchmark fixtures.
|
// Benchmark fixtures.
|
||||||
//
|
//
|
||||||
|
|
||||||
// Number of repeats: 1000
|
abstract class FfiBenchmarkBase extends BenchmarkBase {
|
||||||
// * CPU: Intel(R) Xeon(R) Gold 6154
|
FfiBenchmarkBase(String name) : super(name);
|
||||||
// * Architecture: x64
|
|
||||||
// * 200 - 1100 us
|
|
||||||
const N = 1000;
|
|
||||||
|
|
||||||
class Uint8x01 extends BenchmarkBase {
|
void expectEquals(actual, expected) {
|
||||||
|
if (actual != expected) {
|
||||||
|
throw Exception('$name: Unexpected result: $actual, expected $expected');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void expectApprox(actual, expected) {
|
||||||
|
if (0.999 * expected > actual || actual > 1.001 * expected) {
|
||||||
|
throw Exception('$name: Unexpected result: $actual, expected $expected');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void expectIdentical(actual, expected) {
|
||||||
|
if (!identical(actual, expected)) {
|
||||||
|
throw Exception('$name: Unexpected result: $actual, expected $expected');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Uint8x01 extends FfiBenchmarkBase {
|
||||||
Uint8x01() : super('FfiCall.Uint8x01');
|
Uint8x01() : super('FfiCall.Uint8x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Uint8(N);
|
final int x = doCall1Uint8(N);
|
||||||
if (x != N * 17 + N * 42) {
|
expectEquals(x, N * (17 + 42));
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Uint16x01 extends BenchmarkBase {
|
class Uint16x01 extends FfiBenchmarkBase {
|
||||||
Uint16x01() : super('FfiCall.Uint16x01');
|
Uint16x01() : super('FfiCall.Uint16x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Uint16(N);
|
final int x = doCall1Uint16(N);
|
||||||
if (x != N * 17 + N * 42) {
|
expectEquals(x, N * (17 + 42));
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Uint32x01 extends BenchmarkBase {
|
class Uint32x01 extends FfiBenchmarkBase {
|
||||||
Uint32x01() : super('FfiCall.Uint32x01');
|
Uint32x01() : super('FfiCall.Uint32x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Uint32(N);
|
final int x = doCall1Uint32(N);
|
||||||
if (x != N * (N - 1) / 2 + N * 42) {
|
expectEquals(x, N * (N - 1) / 2 + N * 42);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Uint64x01 extends BenchmarkBase {
|
class Uint64x01 extends FfiBenchmarkBase {
|
||||||
Uint64x01() : super('FfiCall.Uint64x01');
|
Uint64x01() : super('FfiCall.Uint64x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Uint64(N);
|
final int x = doCall1Uint64(N);
|
||||||
if (x != N * (N - 1) / 2 + N * 42) {
|
expectEquals(x, N * (N - 1) / 2 + N * 42);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int8x01 extends BenchmarkBase {
|
class Int8x01 extends FfiBenchmarkBase {
|
||||||
Int8x01() : super('FfiCall.Int8x01');
|
Int8x01() : super('FfiCall.Int8x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Int8(N);
|
final int x = doCall1Int8(N);
|
||||||
if (x != N * 17 + N * 42) {
|
expectEquals(x, N * (17 + 42));
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int16x01 extends BenchmarkBase {
|
class Int16x01 extends FfiBenchmarkBase {
|
||||||
Int16x01() : super('FfiCall.Int16x01');
|
Int16x01() : super('FfiCall.Int16x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Int16(N);
|
final int x = doCall1Int16(N);
|
||||||
if (x != N * 17 + N * 42) {
|
expectEquals(x, N * (17 + 42));
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int32x01 extends BenchmarkBase {
|
class Int32x01 extends FfiBenchmarkBase {
|
||||||
Int32x01() : super('FfiCall.Int32x01');
|
Int32x01() : super('FfiCall.Int32x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Int32(N);
|
final int x = doCall1Int32(N);
|
||||||
if (x != N * (N - 1) / 2 + N * 42) {
|
expectEquals(x, N * (N - 1) / 2 + N * 42);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int32x02 extends BenchmarkBase {
|
class Int32x02 extends FfiBenchmarkBase {
|
||||||
Int32x02() : super('FfiCall.Int32x02');
|
Int32x02() : super('FfiCall.Int32x02');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall2Int32(N);
|
final int x = doCall2Int32(N);
|
||||||
if (x != N * (N - 1) * 2 / 2) {
|
expectEquals(x, N * (N - 1) * 2 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int32x04 extends BenchmarkBase {
|
class Int32x04 extends FfiBenchmarkBase {
|
||||||
Int32x04() : super('FfiCall.Int32x04');
|
Int32x04() : super('FfiCall.Int32x04');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall4Int32(N);
|
final int x = doCall4Int32(N);
|
||||||
if (x != N * (N - 1) * 4 / 2) {
|
expectEquals(x, N * (N - 1) * 4 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int32x10 extends BenchmarkBase {
|
class Int32x10 extends FfiBenchmarkBase {
|
||||||
Int32x10() : super('FfiCall.Int32x10');
|
Int32x10() : super('FfiCall.Int32x10');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall10Int32(N);
|
final int x = doCall10Int32(N);
|
||||||
if (x != N * (N - 1) * 10 / 2) {
|
expectEquals(x, N * (N - 1) * 10 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int32x20 extends BenchmarkBase {
|
class Int32x20 extends FfiBenchmarkBase {
|
||||||
Int32x20() : super('FfiCall.Int32x20');
|
Int32x20() : super('FfiCall.Int32x20');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall20Int32(N);
|
final int x = doCall20Int32(N);
|
||||||
if (x != N * (N - 1) * 20 / 2) {
|
expectEquals(x, N * (N - 1) * 20 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int64x01 extends BenchmarkBase {
|
class Int64x01 extends FfiBenchmarkBase {
|
||||||
Int64x01() : super('FfiCall.Int64x01');
|
Int64x01() : super('FfiCall.Int64x01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Int64(N);
|
final int x = doCall1Int64(N);
|
||||||
if (x != N * (N - 1) / 2 + N * 42) {
|
expectEquals(x, N * (N - 1) / 2 + N * 42);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int64x02 extends BenchmarkBase {
|
class Int64x02 extends FfiBenchmarkBase {
|
||||||
Int64x02() : super('FfiCall.Int64x02');
|
Int64x02() : super('FfiCall.Int64x02');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall2Int64(N);
|
final int x = doCall2Int64(N);
|
||||||
if (x != N * (N - 1) * 2 / 2) {
|
expectEquals(x, N * (N - 1) * 2 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int64x04 extends BenchmarkBase {
|
class Int64x04 extends FfiBenchmarkBase {
|
||||||
Int64x04() : super('FfiCall.Int64x04');
|
Int64x04() : super('FfiCall.Int64x04');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall4Int64(N);
|
final int x = doCall4Int64(N);
|
||||||
if (x != N * (N - 1) * 4 / 2) {
|
expectEquals(x, N * (N - 1) * 4 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int64x10 extends BenchmarkBase {
|
class Int64x10 extends FfiBenchmarkBase {
|
||||||
Int64x10() : super('FfiCall.Int64x10');
|
Int64x10() : super('FfiCall.Int64x10');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall10Int64(N);
|
final int x = doCall10Int64(N);
|
||||||
if (x != N * (N - 1) * 10 / 2) {
|
expectEquals(x, N * (N - 1) * 10 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int64x20 extends BenchmarkBase {
|
class Int64x20 extends FfiBenchmarkBase {
|
||||||
Int64x20() : super('FfiCall.Int64x20');
|
Int64x20() : super('FfiCall.Int64x20');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall20Int64(N);
|
final int x = doCall20Int64(N);
|
||||||
if (x != N * (N - 1) * 20 / 2) {
|
expectEquals(x, N * (N - 1) * 20 / 2);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Int64Mintx01 extends BenchmarkBase {
|
class Int64Mintx01 extends FfiBenchmarkBase {
|
||||||
Int64Mintx01() : super('FfiCall.Int64Mintx01');
|
Int64Mintx01() : super('FfiCall.Int64Mintx01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final int x = doCall1Int64Mint(N);
|
final int x = doCall1Int64Mint(N);
|
||||||
if (x != 0x7FFFFFFF00000000 + N * 42) {
|
expectEquals(x, 0x7FFFFFFF00000000 + N * 42);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Floatx01 extends BenchmarkBase {
|
class Floatx01 extends FfiBenchmarkBase {
|
||||||
Floatx01() : super('FfiCall.Floatx01');
|
Floatx01() : super('FfiCall.Floatx01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final double x = doCall1Float(N);
|
final double x = doCall1Float(N);
|
||||||
final double expected = N * (17.0 + 42);
|
expectApprox(x, N * (17.0 + 42.0));
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Floatx02 extends BenchmarkBase {
|
class Floatx02 extends FfiBenchmarkBase {
|
||||||
Floatx02() : super('FfiCall.Floatx02');
|
Floatx02() : super('FfiCall.Floatx02');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final double x = doCall2Float(N);
|
final double x = doCall2Float(N);
|
||||||
final double expected = N * (1.0 + 2.0);
|
expectApprox(x, N * (1.0 + 2.0));
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Floatx04 extends BenchmarkBase {
|
class Floatx04 extends FfiBenchmarkBase {
|
||||||
Floatx04() : super('FfiCall.Floatx04');
|
Floatx04() : super('FfiCall.Floatx04');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final double x = doCall4Float(N);
|
final double x = doCall4Float(N);
|
||||||
final double expected = N * (1.0 + 2.0 + 3.0 + 4.0);
|
final double expected = N * (1.0 + 2.0 + 3.0 + 4.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Floatx10 extends BenchmarkBase {
|
class Floatx10 extends FfiBenchmarkBase {
|
||||||
Floatx10() : super('FfiCall.Floatx10');
|
Floatx10() : super('FfiCall.Floatx10');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -984,13 +961,11 @@ class Floatx10 extends BenchmarkBase {
|
||||||
final double x = doCall10Float(N);
|
final double x = doCall10Float(N);
|
||||||
final double expected =
|
final double expected =
|
||||||
N * (1.0 + 2.0 + 3.0 + 4.0 + 5.0 + 6.0 + 7.0 + 8.0 + 9.0 + 10.0);
|
N * (1.0 + 2.0 + 3.0 + 4.0 + 5.0 + 6.0 + 7.0 + 8.0 + 9.0 + 10.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Floatx20 extends BenchmarkBase {
|
class Floatx20 extends FfiBenchmarkBase {
|
||||||
Floatx20() : super('FfiCall.Floatx20');
|
Floatx20() : super('FfiCall.Floatx20');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1017,52 +992,44 @@ class Floatx20 extends BenchmarkBase {
|
||||||
18.0 +
|
18.0 +
|
||||||
19.0 +
|
19.0 +
|
||||||
20.0);
|
20.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Doublex01 extends BenchmarkBase {
|
class Doublex01 extends FfiBenchmarkBase {
|
||||||
Doublex01() : super('FfiCall.Doublex01');
|
Doublex01() : super('FfiCall.Doublex01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final double x = doCall1Double(N);
|
final double x = doCall1Double(N);
|
||||||
final double expected = N * (17.0 + 42.0);
|
final double expected = N * (17.0 + 42.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Doublex02 extends BenchmarkBase {
|
class Doublex02 extends FfiBenchmarkBase {
|
||||||
Doublex02() : super('FfiCall.Doublex02');
|
Doublex02() : super('FfiCall.Doublex02');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final double x = doCall2Double(N);
|
final double x = doCall2Double(N);
|
||||||
final double expected = N * (1.0 + 2.0);
|
final double expected = N * (1.0 + 2.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Doublex04 extends BenchmarkBase {
|
class Doublex04 extends FfiBenchmarkBase {
|
||||||
Doublex04() : super('FfiCall.Doublex04');
|
Doublex04() : super('FfiCall.Doublex04');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final double x = doCall4Double(N);
|
final double x = doCall4Double(N);
|
||||||
final double expected = N * (1.0 + 2.0 + 3.0 + 4.0);
|
final double expected = N * (1.0 + 2.0 + 3.0 + 4.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Doublex10 extends BenchmarkBase {
|
class Doublex10 extends FfiBenchmarkBase {
|
||||||
Doublex10() : super('FfiCall.Doublex10');
|
Doublex10() : super('FfiCall.Doublex10');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1070,13 +1037,11 @@ class Doublex10 extends BenchmarkBase {
|
||||||
final double x = doCall10Double(N);
|
final double x = doCall10Double(N);
|
||||||
final double expected =
|
final double expected =
|
||||||
N * (1.0 + 2.0 + 3.0 + 4.0 + 5.0 + 6.0 + 7.0 + 8.0 + 9.0 + 10.0);
|
N * (1.0 + 2.0 + 3.0 + 4.0 + 5.0 + 6.0 + 7.0 + 8.0 + 9.0 + 10.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Doublex20 extends BenchmarkBase {
|
class Doublex20 extends FfiBenchmarkBase {
|
||||||
Doublex20() : super('FfiCall.Doublex20');
|
Doublex20() : super('FfiCall.Doublex20');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1103,16 +1068,14 @@ class Doublex20 extends BenchmarkBase {
|
||||||
18.0 +
|
18.0 +
|
||||||
19.0 +
|
19.0 +
|
||||||
20.0);
|
20.0);
|
||||||
if (0.999 * expected > x || x > 1.001 * expected) {
|
expectApprox(x, expected);
|
||||||
throw Exception('$name: Unexpected result: $x, expected $expected');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PointerUint8x01 extends BenchmarkBase {
|
class PointerUint8x01 extends FfiBenchmarkBase {
|
||||||
PointerUint8x01() : super('FfiCall.PointerUint8x01');
|
PointerUint8x01() : super('FfiCall.PointerUint8x01');
|
||||||
|
|
||||||
Pointer<Uint8> pointer;
|
Pointer<Uint8> pointer = nullptr;
|
||||||
@override
|
@override
|
||||||
void setup() => pointer = calloc(N + 1);
|
void setup() => pointer = calloc(N + 1);
|
||||||
@override
|
@override
|
||||||
|
@ -1121,13 +1084,11 @@ class PointerUint8x01 extends BenchmarkBase {
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final Pointer<Uint8> x = doCall1PointerUint8(N, pointer);
|
final Pointer<Uint8> x = doCall1PointerUint8(N, pointer);
|
||||||
if (x.address != pointer.address + N) {
|
expectApprox(x.address, pointer.address + N);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PointerUint8x02 extends BenchmarkBase {
|
class PointerUint8x02 extends FfiBenchmarkBase {
|
||||||
PointerUint8x02() : super('FfiCall.PointerUint8x02');
|
PointerUint8x02() : super('FfiCall.PointerUint8x02');
|
||||||
|
|
||||||
Pointer<Uint8> pointer, pointer2;
|
Pointer<Uint8> pointer, pointer2;
|
||||||
|
@ -1146,13 +1107,11 @@ class PointerUint8x02 extends BenchmarkBase {
|
||||||
@override
|
@override
|
||||||
void run() {
|
void run() {
|
||||||
final Pointer<Uint8> x = doCall2PointerUint8(N, pointer, pointer2);
|
final Pointer<Uint8> x = doCall2PointerUint8(N, pointer, pointer2);
|
||||||
if (x.address != pointer.address + N * sizeOf<Uint8>()) {
|
expectEquals(x.address, pointer.address + N * sizeOf<Uint8>());
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PointerUint8x04 extends BenchmarkBase {
|
class PointerUint8x04 extends FfiBenchmarkBase {
|
||||||
PointerUint8x04() : super('FfiCall.PointerUint8x04');
|
PointerUint8x04() : super('FfiCall.PointerUint8x04');
|
||||||
|
|
||||||
Pointer<Uint8> pointer, pointer2, pointer3, pointer4;
|
Pointer<Uint8> pointer, pointer2, pointer3, pointer4;
|
||||||
|
@ -1174,13 +1133,11 @@ class PointerUint8x04 extends BenchmarkBase {
|
||||||
void run() {
|
void run() {
|
||||||
final Pointer<Uint8> x =
|
final Pointer<Uint8> x =
|
||||||
doCall4PointerUint8(N, pointer, pointer2, pointer3, pointer4);
|
doCall4PointerUint8(N, pointer, pointer2, pointer3, pointer4);
|
||||||
if (x.address != pointer.address + N * sizeOf<Uint8>()) {
|
expectEquals(x.address, pointer.address + N * sizeOf<Uint8>());
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PointerUint8x10 extends BenchmarkBase {
|
class PointerUint8x10 extends FfiBenchmarkBase {
|
||||||
PointerUint8x10() : super('FfiCall.PointerUint8x10');
|
PointerUint8x10() : super('FfiCall.PointerUint8x10');
|
||||||
|
|
||||||
Pointer<Uint8> pointer,
|
Pointer<Uint8> pointer,
|
||||||
|
@ -1227,13 +1184,11 @@ class PointerUint8x10 extends BenchmarkBase {
|
||||||
pointer8,
|
pointer8,
|
||||||
pointer9,
|
pointer9,
|
||||||
pointer10);
|
pointer10);
|
||||||
if (x.address != pointer.address + N * sizeOf<Uint8>()) {
|
expectEquals(x.address, pointer.address + N * sizeOf<Uint8>());
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PointerUint8x20 extends BenchmarkBase {
|
class PointerUint8x20 extends FfiBenchmarkBase {
|
||||||
PointerUint8x20() : super('FfiCall.PointerUint8x20');
|
PointerUint8x20() : super('FfiCall.PointerUint8x20');
|
||||||
|
|
||||||
Pointer<Uint8> pointer,
|
Pointer<Uint8> pointer,
|
||||||
|
@ -1310,9 +1265,7 @@ class PointerUint8x20 extends BenchmarkBase {
|
||||||
pointer18,
|
pointer18,
|
||||||
pointer19,
|
pointer19,
|
||||||
pointer20);
|
pointer20);
|
||||||
if (x.address != pointer.address + N * sizeOf<Uint8>()) {
|
expectEquals(x.address, pointer.address + N * sizeOf<Uint8>());
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1321,7 +1274,7 @@ class MyClass {
|
||||||
MyClass(this.a);
|
MyClass(this.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Handlex01 extends BenchmarkBase {
|
class Handlex01 extends FfiBenchmarkBase {
|
||||||
Handlex01() : super('FfiCall.Handlex01');
|
Handlex01() : super('FfiCall.Handlex01');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1329,13 +1282,11 @@ class Handlex01 extends BenchmarkBase {
|
||||||
final p1 = MyClass(123);
|
final p1 = MyClass(123);
|
||||||
final x = doCall1Handle(N, p1);
|
final x = doCall1Handle(N, p1);
|
||||||
|
|
||||||
if (!identical(p1, x)) {
|
expectIdentical(x, p1);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Handlex02 extends BenchmarkBase {
|
class Handlex02 extends FfiBenchmarkBase {
|
||||||
Handlex02() : super('FfiCall.Handlex02');
|
Handlex02() : super('FfiCall.Handlex02');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1344,13 +1295,11 @@ class Handlex02 extends BenchmarkBase {
|
||||||
final p2 = MyClass(2);
|
final p2 = MyClass(2);
|
||||||
final x = doCall2Handle(N, p1, p2);
|
final x = doCall2Handle(N, p1, p2);
|
||||||
|
|
||||||
if (!identical(p1, x)) {
|
expectIdentical(x, p1);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Handlex04 extends BenchmarkBase {
|
class Handlex04 extends FfiBenchmarkBase {
|
||||||
Handlex04() : super('FfiCall.Handlex04');
|
Handlex04() : super('FfiCall.Handlex04');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1361,13 +1310,11 @@ class Handlex04 extends BenchmarkBase {
|
||||||
final p4 = MyClass(4);
|
final p4 = MyClass(4);
|
||||||
final x = doCall4Handle(N, p1, p2, p3, p4);
|
final x = doCall4Handle(N, p1, p2, p3, p4);
|
||||||
|
|
||||||
if (!identical(p1, x)) {
|
expectIdentical(x, p1);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Handlex10 extends BenchmarkBase {
|
class Handlex10 extends FfiBenchmarkBase {
|
||||||
Handlex10() : super('FfiCall.Handlex10');
|
Handlex10() : super('FfiCall.Handlex10');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1384,13 +1331,11 @@ class Handlex10 extends BenchmarkBase {
|
||||||
final p10 = MyClass(10);
|
final p10 = MyClass(10);
|
||||||
final x = doCall10Handle(N, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
final x = doCall10Handle(N, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
|
||||||
|
|
||||||
if (!identical(p1, x)) {
|
expectIdentical(x, p1);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Handlex20 extends BenchmarkBase {
|
class Handlex20 extends FfiBenchmarkBase {
|
||||||
Handlex20() : super('FfiCall.Handlex20');
|
Handlex20() : super('FfiCall.Handlex20');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1418,9 +1363,7 @@ class Handlex20 extends BenchmarkBase {
|
||||||
final x = doCall20Handle(N, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11,
|
final x = doCall20Handle(N, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11,
|
||||||
p12, p13, p14, p15, p16, p17, p18, p19, p20);
|
p12, p13, p14, p15, p16, p17, p18, p19, p20);
|
||||||
|
|
||||||
if (!identical(p1, x)) {
|
expectIdentical(p1, x);
|
||||||
throw Exception('$name: Unexpected result: $x');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue