1+ import 'dart:async' ;
2+
13import 'package:objectbox_benchmark/benchmark.dart' ;
4+ import 'package:objectbox_benchmark/model.dart' ;
25import 'package:objectbox_benchmark/objectbox.g.dart' ;
36
47const 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
1621class 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