File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 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 'dart:convert' ;
6+ import 'dart:io' ;
7+
8+ import 'package:pub_dev/package/overrides.dart' ;
9+ import 'package:pub_dev/search/mem_index.dart' ;
10+ import 'package:pub_dev/search/models.dart' ;
11+ import 'package:pub_dev/search/search_service.dart' ;
12+
13+ /// Loads a search snapshot and executes queries on it, benchmarking their total time to complete.
14+ Future <void > main (List <String > args) async {
15+ // Assumes that the first argument is a search snapshot file.
16+ final file = File (args.first);
17+ final content =
18+ json.decode (utf8.decode (gzip.decode (await file.readAsBytes ())))
19+ as Map <String , Object ?>;
20+ final snapshot = SearchSnapshot .fromJson (content);
21+ snapshot.documents!
22+ .removeWhere ((packageName, doc) => isSoftRemoved (packageName));
23+ final index = InMemoryPackageIndex (documents: snapshot.documents! .values);
24+
25+ // NOTE: please add more queries to this list, especially if there is a performance bottleneck.
26+ final queries = [
27+ 'json' ,
28+ 'camera' ,
29+ 'android camera' ,
30+ 'sql database' ,
31+ ];
32+
33+ final sw = Stopwatch ()..start ();
34+ var count = 0 ;
35+ for (var i = 0 ; i < 100 ; i++ ) {
36+ index.search (ServiceSearchQuery .parse (query: queries[i % queries.length]));
37+ count++ ;
38+ }
39+ sw.stop ();
40+ print ('${(sw .elapsedMilliseconds / count ).toStringAsFixed (2 )} ms/request' );
41+ }
You can’t perform that action at this time.
0 commit comments