-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathquery_performance.dart
More file actions
202 lines (181 loc) · 5.74 KB
/
query_performance.dart
File metadata and controls
202 lines (181 loc) · 5.74 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import 'package:flutter/material.dart';
import 'package:ndk/entities.dart';
import 'package:ndk/ndk.dart';
import 'package:ndk_rust_verifier/data_layer/repositories/verifiers/rust_event_verifier.dart';
class MyVerifiers {
static final bip340Verifier = Bip340EventVerifier();
static final bip340VerifierNoIsolate = Bip340EventVerifier(useIsolate: false);
static final rustVerifier = RustEventVerifier();
}
class QueryPerformancePage extends StatefulWidget {
final Ndk ndk;
const QueryPerformancePage({super.key, required this.ndk});
@override
State<QueryPerformancePage> createState() => _QueryPerformancePageState();
}
class _QueryPerformancePageState extends State<QueryPerformancePage> {
int _eventCount = 100;
String _bip340Time = '';
String _bip340NoIsolateTime = '';
String _rustTime = '';
bool _isVerifyingBip340 = false;
bool _isVerifyingBip340NoIsolate = false;
bool _isVerifyingRust = false;
static const relays = ["wss://relay.primal.net"];
final ndkBip340 = Ndk(NdkConfig(
eventVerifier: MyVerifiers.bip340Verifier,
cache: MemCacheManager(),
bootstrapRelays: relays,
logLevel: LogLevel.warning
));
final ndkBip340NoIsolate = Ndk(NdkConfig(
eventVerifier: MyVerifiers.bip340VerifierNoIsolate,
cache: MemCacheManager(),
bootstrapRelays: relays,
));
final ndkRust = Ndk(NdkConfig(
eventVerifier: MyVerifiers.rustVerifier,
cache: MemCacheManager(),
bootstrapRelays: relays,
));
Future<void> _runBip340Query() async {
setState(() {
_isVerifyingBip340 = true;
_bip340Time = '';
});
final stopwatch = Stopwatch()..start();
await _runQuery(ndkBip340);
stopwatch.stop();
setState(() {
_isVerifyingBip340 = false;
_bip340Time = '${stopwatch.elapsedMilliseconds}ms';
});
}
Future<void> _runBip340NoIsolateQuery() async {
setState(() {
_isVerifyingBip340NoIsolate = true;
_bip340NoIsolateTime = '';
});
final stopwatch = Stopwatch()..start();
await _runQuery(ndkBip340NoIsolate);
stopwatch.stop();
setState(() {
_isVerifyingBip340NoIsolate = false;
_bip340NoIsolateTime = '${stopwatch.elapsedMilliseconds}ms';
});
}
Future<void> _runRustQuery() async {
setState(() {
_isVerifyingRust = true;
_rustTime = '';
});
final stopwatch = Stopwatch()..start();
await _runQuery(ndkRust);
stopwatch.stop();
setState(() {
_isVerifyingRust = false;
_rustTime = '${stopwatch.elapsedMilliseconds}ms';
});
}
_runQuery(Ndk ndk) async {
final query = ndk.requests.query(
filters: [
Filter(
kinds: [1],
limit: _eventCount,
)
],
cacheRead: false,
cacheWrite: false,
);
await query.future;
}
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Query Performance'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextField(
decoration: const InputDecoration(
labelText: 'Event Count',
border: OutlineInputBorder(),
),
keyboardType: TextInputType.number,
onChanged: (value) {
setState(() {
_eventCount = int.tryParse(value) ?? 100;
});
},
controller: TextEditingController(text: _eventCount.toString()),
),
const SizedBox(height: 24),
ElevatedButton(
onPressed: _isVerifyingBip340 ? null : _runBip340Query,
child: _isVerifyingBip340
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text('Run with BIP340'),
),
const SizedBox(height: 8),
Text(
_bip340Time.isEmpty ? 'Not run yet' : 'Time: $_bip340Time',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge,
),
const SizedBox(height: 24),
ElevatedButton(
onPressed: _isVerifyingBip340NoIsolate ? null : _runBip340NoIsolateQuery,
child: _isVerifyingBip340NoIsolate
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text('Run with BIP340 (no isolate)'),
),
const SizedBox(height: 8),
Text(
_bip340NoIsolateTime.isEmpty ? 'Not run yet' : 'Time: $_bip340NoIsolateTime',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge,
),
const SizedBox(height: 24),
ElevatedButton(
onPressed: _isVerifyingRust ? null : _runRustQuery,
child: _isVerifyingRust
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text('Run with Rust'),
),
const SizedBox(height: 8),
Text(
_rustTime.isEmpty ? 'Not run yet' : 'Time: $_rustTime',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge,
),
],
),
),
);
}
}