Files
sdk/benchmarks/IntegerSetLookup/dart/IntegerSetLookup.dart
T
Eric Seidel 4c20cedd30 Fix analysis issues in benchmarks/ directory
Now that I'm able to open the entire SDK in VSC, I'm fixing some
of the analysis issues in various files (carefully) without changing
their meaning.

In this case, I removed unnecessary imports from benchmarks.
In regexp_benchmark I ignored one warning which likely would
have changed the behavior of the code.

BUG=https://github.com/dart-lang/sdk/issues/52419

Change-Id: I9a195a4e45121313bd9f065f2579a165c3fec05b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303901
Auto-Submit: Eric Seidel <eric@shorebird.dev>
Reviewed-by: William Hesse <whesse@google.com>
Commit-Queue: William Hesse <whesse@google.com>
2023-05-17 09:14:50 +00:00

46 lines
1.3 KiB
Dart

// Copyright (c) 2022, 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 'dart:collection';
// Benchmark for https://github.com/dart-lang/sdk/issues/48641.
//
// Measures the average time needed for a lookup in Sets of integers.
import 'dart:math';
import 'package:benchmark_harness/benchmark_harness.dart';
class SetBenchmark extends BenchmarkBase {
SetBenchmark(String name, this.mySet) : super(name);
final Set<int> mySet;
@override
void run() {
mySet.contains(123456789);
}
}
void main() {
final list = [
for (int i = 0; i < 14790; i++) (i + 1) * 0x10000000 + 123456789
];
final r = Random();
final randomList = List<int>.generate(14790, (_) => r.nextInt(1 << 31));
final benchmarks = [
() => SetBenchmark('IntegerSetLookup.DefaultHashSet', {...list}),
() =>
SetBenchmark('IntegerSetLookup.HashSet', HashSet<int>()..addAll(list)),
() =>
SetBenchmark('IntegerSetLookup.DefaultHashSet_Random', {...randomList}),
() => SetBenchmark(
'IntegerSetLookup.HashSet_Random', HashSet<int>()..addAll(randomList)),
];
for (final benchmark in benchmarks) {
benchmark().report();
}
}