Skip to content

Commit bc17724

Browse files
aamCommit Queue
authored and
Commit Queue
committed
[benchmarks] Add LongStringCompare benchmark that measure string comparison performance.
BUG=#50190 TEST=ci Change-Id: I1cb93455283b19cf1a712132920b7d3e1dabcd8a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/269380 Commit-Queue: Alexander Aprelev <[email protected]> Reviewed-by: Siva Annamalai <[email protected]>
1 parent 6cb9397 commit bc17724

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// Measure performance of string comparison.
6+
7+
import 'package:benchmark_harness/benchmark_harness.dart';
8+
9+
class LongStringCompare extends BenchmarkBase {
10+
late String s, t;
11+
12+
String generateLongString() {
13+
var s = "abcdefgh";
14+
for (int i = 0; i < 20; i++) {
15+
s = "$s ghijkl $s";
16+
}
17+
return s;
18+
}
19+
20+
LongStringCompare() : super('LongStringCompare') {
21+
s = generateLongString();
22+
t = s;
23+
// Difference in two strings goes in the middle.
24+
s += "." + s;
25+
t += "!" + t;
26+
}
27+
28+
@override
29+
void warmup() {
30+
for (int i = 0; i < 4; i++) {
31+
run();
32+
}
33+
}
34+
35+
@override
36+
void run() {
37+
bool b = true;
38+
for (int i = 0; i < 5; i++) {
39+
b &= (s == t);
40+
}
41+
}
42+
}
43+
44+
void main() {
45+
LongStringCompare().report();
46+
}

0 commit comments

Comments
 (0)