runFullBenchmark static method
Run full benchmark suite
Implementation
static Future<List<BenchmarkResult>> runFullBenchmark({
required String dbPath,
Function(String)? onProgress,
}) async {
final results = <BenchmarkResult>[];
// Test data - English samples
final shortText = "Apple is delicious";
final mediumText =
"Apples are red fruits rich in vitamins. Eating them daily is good for health.";
final longText =
"Apples belong to the rose family and are one of the most widely cultivated fruits in the world. "
"They are rich in vitamin C and dietary fiber with many varieties. "
"The skin contains many antioxidants, so eating with skin is recommended.";
onProgress?.call("Starting tokenization benchmark...");
// 1. Tokenization benchmark
results.add(await benchmarkTokenize(shortText));
results.add(await benchmarkTokenize(mediumText));
results.add(await benchmarkTokenize(longText));
onProgress?.call("Starting embedding benchmark...");
// 2. Embedding benchmark
results.add(await benchmarkEmbed(shortText));
results.add(await benchmarkEmbed(mediumText));
results.add(await benchmarkEmbed(longText));
onProgress?.call("Batch embedding benchmark...");
// 2.5 Batch embedding benchmark
final batchTexts = [
shortText,
mediumText,
longText,
"Dogs are cute and loyal",
"Cats are agile hunters",
"Cars are fast vehicles",
"Computers are convenient tools",
"Paris is the capital of France",
"The ocean is vast and blue",
"Mountains are tall and majestic",
];
// Sequential embedding (for comparison)
results.add(
await benchmark(
'Sequential Embed (10 texts)',
() async {
for (final text in batchTexts) {
await EmbeddingService.embed(text);
}
},
iterations: 3,
category: BenchmarkCategory.onnx,
),
);
// Batch embedding
results.add(
await benchmark(
'Batch Embed (10 texts)',
() async {
await EmbeddingService.embedBatch(batchTexts, concurrency: 4);
},
iterations: 3,
category: BenchmarkCategory.onnx,
),
);
onProgress?.call("Preparing search benchmark...");
// 3. Search benchmark data preparation
final testDbPath =
"${(await getApplicationDocumentsDirectory()).path}/benchmark_db.sqlite";
await initDb(dbPath: testDbPath);
// Sample documents (20 texts x 5 = 100 documents)
final sampleTexts = [
"Apple is delicious",
"Banana is yellow",
"Orange is round",
"Grape is sweet",
"Watermelon is big",
"Dog is cute",
"Cat is agile",
"Rabbit is fast",
"Turtle is slow",
"Monkey is smart",
"Car is fast",
"Bicycle is healthy",
"Airplane flies in the sky",
"Ship crosses the ocean",
"Train arrives on time",
"Computer is convenient",
"Smartphone is essential",
"Tablet is light",
"Laptop is portable",
"Desktop is powerful",
];
// Create 100 documents (20 texts x 5 repeats)
for (var i = 0; i < 5; i++) {
for (final text in sampleTexts) {
final emb = await EmbeddingService.embed(text);
await addDocument(
dbPath: testDbPath,
content: "$text ($i)",
embedding: emb,
);
}
}
// Rebuild HNSW index after adding documents
await rebuildHnswIndex(dbPath: testDbPath);
onProgress?.call("Running search benchmark...");
final queryEmb = await EmbeddingService.embed("fruit");
// Search benchmark (100 documents)
results.add(await benchmarkSearch(testDbPath, queryEmb, 100));
// Cleanup
await File(testDbPath).delete();
onProgress?.call("Benchmark complete!");
return results;
}