mirror of
https://github.com/dart-lang/sdk
synced 2024-10-02 23:49:17 +00:00
b6aa2976dc
The benchmarks were using a range of antipatterns that did not do what the authors thought they did. It seems that the authors thought the warmup method has to run for a while and do the full warmup, but the truth is that the harness will do that for you by running the warmup function in a timed loop. Instead these patterns just wasted time by making the warmup more expensive and complex than needed. This change just removes the warmup overrides since none of them do anything positive. This change prepares us for future improvements to the benchmark harness. Fixes: b/324874055 Change-Id: Ib7c282123a2151614bc95a105a30e67221f11315 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352022 Reviewed-by: William Hesse <whesse@google.com> Commit-Queue: Jonas Termansen <sortie@google.com>
47 lines
1.4 KiB
Dart
47 lines
1.4 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.
|
|
//
|
|
// Measure performance of string comparison.
|
|
|
|
// Using string interpolation could change what this test is measuring.
|
|
// ignore_for_file: prefer_interpolation_to_compose_strings
|
|
|
|
import 'package:benchmark_harness/benchmark_harness.dart';
|
|
|
|
int equalCount = 0;
|
|
|
|
class LongStringCompare extends BenchmarkBase {
|
|
final int reps;
|
|
final List<String> s = [];
|
|
|
|
String generateLongString(int lengthPower) {
|
|
return 'abc' * (1 << lengthPower) + 'def';
|
|
}
|
|
|
|
LongStringCompare(int lengthPower, this.reps)
|
|
: super('LongStringCompare.${1 << lengthPower}.${reps}reps') {
|
|
final single = generateLongString(lengthPower);
|
|
s.add(single + '.' + single);
|
|
s.add(single + '!' + single);
|
|
}
|
|
|
|
@override
|
|
void run() {
|
|
for (int i = 0; i < reps; i++) {
|
|
// Make string comparison code hoisting harder for the compiler to do.
|
|
final bool comparison = s[i % 2] == s[(i + 1) % 2];
|
|
if (comparison) {
|
|
equalCount++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
LongStringCompare(1, 3000).report();
|
|
LongStringCompare(5, 1000).report();
|
|
LongStringCompare(10, 30).report();
|
|
if (equalCount > 0) throw StateError('Unexpected equalCount: $equalCount');
|
|
}
|