Skip to content

Commit 73f43ae

Browse files
authored
Tool for local SDK search index benchmark (#8751)
1 parent 00f53e0 commit 73f43ae

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2024, 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+
import 'package:pub_dev/search/flutter_sdk_mem_index.dart';
6+
7+
/// Loads a Dart SDK search snapshot and executes queries on it, benchmarking their total time to complete.
8+
Future<void> main() async {
9+
final index = await createFlutterSdkMemIndex();
10+
11+
// NOTE: please add more queries to this list, especially if there is a performance bottleneck.
12+
final queries = [
13+
'chart',
14+
'json',
15+
'camera',
16+
'android camera',
17+
'sql database',
18+
];
19+
20+
final sw = Stopwatch()..start();
21+
var count = 0;
22+
for (var i = 0; i < 100; i++) {
23+
index!.search(queries[i % queries.length]);
24+
count++;
25+
}
26+
sw.stop();
27+
print('${(sw.elapsedMilliseconds / count).toStringAsFixed(2)} ms/request');
28+
}

0 commit comments

Comments
 (0)