-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
68 lines (58 loc) · 1.88 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
import 'package:benchmark/benchmark.dart';
import 'package:cbl_flutter/cbl_flutter.dart';
import 'package:cbl_provider/cbl_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:logging/logging.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
loadDocumentsJson = _loadDocumentsFromAssets;
await CouchbaseLiteFlutter.init();
await runBenchmark(
onProgress: WidgetsBinding.instance.scheduleForcedFrame,
);
}
Future<String> _loadDocumentsFromAssets() =>
rootBundle.loadString('packages/benchmark/src/fixture/documents.json');
Future<void> runBenchmark({VoidCallback? onProgress}) {
final runPlan = BenchmarkPlan(
warmUpDuration: const FixedTimedDuration(Duration(milliseconds: 200)),
benchmarkDuration: const FixedTimedDuration(Duration(seconds: 20)),
runConfigurations: [
BenchmarkRunConfiguration(
benchmark: const CreateDocumentBenchmark(),
databaseProvider: CblProvider(),
arguments: ParameterArguments((b) {
b
..add(execution, Execution.async)
..add(batchSize, 100);
}),
)
],
);
final runner = BenchmarkPlanRunner(
plan: runPlan,
logger: Logger.root,
catchExceptions: true,
observer: _BenchmarkObserver(onProgress: onProgress),
)..start();
return runner.done;
}
class _BenchmarkObserver extends BenchmarkPlanObserver {
_BenchmarkObserver({this.onProgress});
final VoidCallback? onProgress;
int? _lastProgress;
@override
void didChangeBenchmarkRunner(
BenchmarkPlanRunner runner,
BenchmarkRunConfiguration configuration,
BenchmarkRunner benchmarkRunner,
) {
final progress = (benchmarkRunner.progress * 100).round();
if (_lastProgress != progress) {
print('progress: $progress');
_lastProgress = progress;
onProgress?.call();
}
}
}