Skip to content

Commit 561baea

Browse files
Benchmark: runAsync, also return values from transaction (#19)
1 parent cee3345 commit 561baea

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

benchmark/bin/write.dart

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void main() async {
1616
await PutQueued().report();
1717
await RunInTx().report();
1818
await RunInTxAsync().report();
19+
await RunAsync().report();
1920
}
2021

2122
class Put extends DbBenchmark {
@@ -106,7 +107,10 @@ class RunInTx extends DbBenchmark {
106107

107108
@override
108109
void runIteration(int i) {
109-
store.runInTransaction(TxMode.write, () => items.forEach(box.put));
110+
store.runInTransaction(TxMode.write, () {
111+
box.putMany(items);
112+
return box.getAll();
113+
});
110114
}
111115
}
112116

@@ -116,11 +120,27 @@ class RunInTxAsync extends DbBenchmark {
116120
RunInTxAsync() : super('$RunInTxAsync');
117121

118122
@override
119-
Future<void> runIteration(int iteration) {
123+
Future<List<TestEntity>> runIteration(int iteration) async {
120124
return store.runInTransactionAsync(TxMode.write,
121-
(Store store, List<TestEntity> items) {
125+
(Store store, List<TestEntity> param) {
122126
final box = store.box<TestEntity>();
123-
items.forEach(box.put);
127+
box.putMany(param);
128+
return box.getAll();
129+
}, items);
130+
}
131+
}
132+
133+
class RunAsync extends DbBenchmark {
134+
final items = prepareTestEntities(count, assignedIds: true);
135+
136+
RunAsync() : super('$RunAsync');
137+
138+
@override
139+
Future<List<TestEntity>> runIteration(int iteration) {
140+
return store.runAsync((Store store, List<TestEntity> param) {
141+
final box = store.box<TestEntity>();
142+
box.putMany(param);
143+
return box.getAll();
124144
}, items);
125145
}
126146
}

0 commit comments

Comments
 (0)