-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.dart
91 lines (81 loc) · 2.7 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import 'dart:math';
import 'dart:developer' as dev;
import 'package:edge_db_benchmarks/databases/isar_db.dart';
import 'package:edge_db_benchmarks/databases/object_box_db.dart';
import 'package:edge_db_benchmarks/databases/sqlite_db.dart';
import 'package:edge_db_benchmarks/models/embedding.dart';
import 'package:flutter/material.dart';
void main() async {
runApp(const MainApp());
final embeddings = <Embedding>[];
for (int i = 0; i < count; i++) {
embeddings.add(Embedding(embedding: getRandom512DoubleList()));
}
await benchmarkSqlite(embeddings);
await benchmarkObjectBox(embeddings);
await benchmarkIsar(embeddings);
}
const count = 100000;
Future<void> benchmarkSqlite(List<Embedding> embeddings) async {
await SqliteDB.instance.init();
final stopwatch = Stopwatch()..start();
await SqliteDB.instance.insertMultipleEmbeddings(embeddings);
stopwatch.stop();
dev.log(
'SQLite: $count embeddings inserted in ${stopwatch.elapsedMilliseconds} ms');
stopwatch.reset();
stopwatch.start();
final response = await SqliteDB.instance.embeddings();
stopwatch.stop();
dev.log(
'SQLite: ${response.length} embeddings retrieved in ${stopwatch.elapsedMilliseconds} ms');
}
Future<void> benchmarkObjectBox(List<Embedding> embeddings) async {
await ObjectBoxDB.instance.init();
final stopwatch = Stopwatch()..start();
await ObjectBoxDB.instance.insertMultipleEmbeddings(embeddings);
stopwatch.stop();
dev.log(
'ObjectBox: $count embeddings inserted in ${stopwatch.elapsedMilliseconds} ms');
stopwatch.reset();
stopwatch.start();
final response = await ObjectBoxDB.instance.embeddings();
stopwatch.stop();
dev.log(
'ObjectBox: ${response.length} embeddings retrieved in ${stopwatch.elapsedMilliseconds} ms');
}
Future<void> benchmarkIsar(List<Embedding> embeddings) async {
await IsarDB.instance.init();
final stopwatch = Stopwatch()..start();
await IsarDB.instance.putMany(embeddings);
stopwatch.stop();
dev.log(
'Isar: $count embeddings inserted in ${stopwatch.elapsedMilliseconds} ms');
stopwatch.reset();
stopwatch.start();
final response = await IsarDB.instance.embeddings();
stopwatch.stop();
dev.log(
'Isar: ${response.length} embeddings retrieved in ${stopwatch.elapsedMilliseconds} ms');
}
List<double> getRandom512DoubleList() {
final random = Random();
final list = <double>[];
for (var i = 0; i < 512; i++) {
list.add(random.nextDouble());
}
return list;
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: Text('Hello World!'),
),
),
);
}
}