File tree 1 file changed +46
-0
lines changed
benchmarks/StringCompare/dart
1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments