Skip to content

Commit 8e0021a

Browse files
Benchmark: compare runInTransaction against runInTransactionAsync (#19)
1 parent 9ceeccc commit 8e0021a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

benchmark/bin/write.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import 'dart:async';
2+
13
import 'package:objectbox_benchmark/benchmark.dart';
4+
import 'package:objectbox_benchmark/model.dart';
25
import 'package:objectbox_benchmark/objectbox.g.dart';
36

47
const count = 10000;
@@ -11,6 +14,8 @@ void main() async {
1114
await PutAsync2().report();
1215
await PutAsync3().report();
1316
await PutQueued().report();
17+
await RunInTx().report();
18+
await RunInTxAsync().report();
1419
}
1520

1621
class Put extends DbBenchmark {
@@ -93,3 +98,29 @@ class PutQueued extends DbBenchmark {
9398
store.awaitAsyncSubmitted();
9499
}
95100
}
101+
102+
class RunInTx extends DbBenchmark {
103+
final items = prepareTestEntities(count, assignedIds: true);
104+
105+
RunInTx() : super('$RunInTx');
106+
107+
@override
108+
void runIteration(int i) {
109+
store.runInTransaction(TxMode.write, () => items.forEach(box.put));
110+
}
111+
}
112+
113+
class RunInTxAsync extends DbBenchmark {
114+
final items = prepareTestEntities(count, assignedIds: true);
115+
116+
RunInTxAsync() : super('$RunInTxAsync');
117+
118+
@override
119+
Future<void> runIteration(int iteration) {
120+
return store.runInTransactionAsync(
121+
TxMode.write,
122+
(Store store, List<TestEntity> items) =>
123+
items.forEach(store.box<TestEntity>().put),
124+
items);
125+
}
126+
}

0 commit comments

Comments
 (0)