mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
[benchmarks] Add LongStringCompare benchmark that measure string comparison performance.
BUG=https://github.com/dart-lang/sdk/issues/50190 TEST=ci Change-Id: I1cb93455283b19cf1a712132920b7d3e1dabcd8a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/269380 Commit-Queue: Alexander Aprelev <aam@google.com> Reviewed-by: Siva Annamalai <asiva@google.com>
This commit is contained in:
parent
6cb9397f59
commit
bc17724feb
1 changed files with 46 additions and 0 deletions
46
benchmarks/StringCompare/dart/LongStringCompare.dart
Normal file
46
benchmarks/StringCompare/dart/LongStringCompare.dart
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
import 'package:benchmark_harness/benchmark_harness.dart';
|
||||||
|
|
||||||
|
class LongStringCompare extends BenchmarkBase {
|
||||||
|
late String s, t;
|
||||||
|
|
||||||
|
String generateLongString() {
|
||||||
|
var s = "abcdefgh";
|
||||||
|
for (int i = 0; i < 20; i++) {
|
||||||
|
s = "$s ghijkl $s";
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
LongStringCompare() : super('LongStringCompare') {
|
||||||
|
s = generateLongString();
|
||||||
|
t = s;
|
||||||
|
// Difference in two strings goes in the middle.
|
||||||
|
s += "." + s;
|
||||||
|
t += "!" + t;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void warmup() {
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void run() {
|
||||||
|
bool b = true;
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
b &= (s == t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
LongStringCompare().report();
|
||||||
|
}
|
Loading…
Reference in a new issue