From 16be64abed899f0d96af748303811187167d491b Mon Sep 17 00:00:00 2001 From: Istvan Soos Date: Tue, 31 Dec 2024 14:24:25 +0100 Subject: [PATCH 1/2] Mini-benchmark for indexed blob. --- app/bin/tools/indexed_blob_benchmark.dart | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 app/bin/tools/indexed_blob_benchmark.dart diff --git a/app/bin/tools/indexed_blob_benchmark.dart b/app/bin/tools/indexed_blob_benchmark.dart new file mode 100644 index 0000000000..f74f8d7e6b --- /dev/null +++ b/app/bin/tools/indexed_blob_benchmark.dart @@ -0,0 +1,51 @@ +// Copyright (c) 2024, 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. + +import 'dart:io'; + +import 'package:indexed_blob/indexed_blob.dart'; +import 'package:path/path.dart' as p; +import 'package:pub_dev/shared/utils.dart'; + +// 27.826 index bytes/entry. +// 0.0647 ms/(load+lookup) +// 0.060964 ms/lookup +Future main() async { + final index = await withTempDirectory((dir) async { + final blobFile = File(p.join(dir.path, 'blob.data')); + final builder = IndexedBlobBuilder(blobFile.openWrite()); + for (var i = 0; i < 1000; i++) { + await builder.addFile('doc/$i.html', Stream.value(List.filled(2000, 0))); + } + final index = await builder.buildIndex('123'); + + final blobIndex = File(p.join(dir.path, 'blob.index')); + await blobIndex.writeAsBytes(index.asBytes()); + + print('${blobIndex.lengthSync() / 1000} index bytes/entry.'); + + final bytes = await blobIndex.readAsBytes(); + final loadSw = Stopwatch()..start(); + for (var r = 0; r < 10000; r++) { + final x = BlobIndex.fromBytes(bytes); + final r = x.lookup('doc/555.html'); + r!.start; + x.lookup('doc/555.txt'); + } + loadSw.stop(); + print('${loadSw.elapsedMilliseconds / 10000} ms/(load+lookup)'); + + return index; + }); + + final lookupSw = Stopwatch()..start(); + for (var r = 0; r < 1000; r++) { + for (var i = 0; i < 1000; i++) { + index.lookup('doc/$i.html'); + index.lookup('doc/$i.txt'); + } + } + lookupSw.stop(); + print('${lookupSw.elapsed.inMilliseconds / 1000 / 1000} ms/lookup'); +} From 141ecc4fb618b110ca67c6799e407a236a98d011 Mon Sep 17 00:00:00 2001 From: Istvan Soos Date: Mon, 6 Jan 2025 14:53:33 +0100 Subject: [PATCH 2/2] More comment and documentation. --- app/bin/tools/indexed_blob_benchmark.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/bin/tools/indexed_blob_benchmark.dart b/app/bin/tools/indexed_blob_benchmark.dart index f74f8d7e6b..a3c8072803 100644 --- a/app/bin/tools/indexed_blob_benchmark.dart +++ b/app/bin/tools/indexed_blob_benchmark.dart @@ -8,9 +8,13 @@ import 'package:indexed_blob/indexed_blob.dart'; import 'package:path/path.dart' as p; import 'package:pub_dev/shared/utils.dart'; -// 27.826 index bytes/entry. -// 0.0647 ms/(load+lookup) -// 0.060964 ms/lookup +/// Runs a synthetic benchmark by creating and index file, loading it and running +/// lookup multiple times. +/// +/// Note: these are some non-representative numbers from local benchmarking, for future reference: +/// 27.826 index bytes/entry. +/// 0.0647 ms/(load+lookup) +/// 0.060964 ms/lookup Future main() async { final index = await withTempDirectory((dir) async { final blobFile = File(p.join(dir.path, 'blob.data'));