-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark.dart
More file actions
33 lines (28 loc) · 852 Bytes
/
benchmark.dart
File metadata and controls
33 lines (28 loc) · 852 Bytes
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
import 'dart:io';
import 'dart:math';
import 'dart:typed_data';
import 'package:maxminddb/maxminddb.dart';
void main(List<String> args) async {
late MaxMindDatabase database;
if (args.isNotEmpty && args[0] == 'memory') {
database = await MaxMindDatabase.memory(
File('GeoLite2-City.mmdb').readAsBytesSync(),
);
} else {
database = await MaxMindDatabase.file(File('GeoLite2-City.mmdb'));
}
final random = Random();
final addresses = <String>[];
for (var i = 0; i < 10000; i++) {
final bytes = Uint8List(16);
for (var i = 0; i < 16; i++) {
bytes[i] = random.nextInt(0xff);
}
addresses.add(InternetAddress.fromRawAddress(bytes).address);
}
final start = DateTime.now();
for (final address in addresses) {
await database.search(address);
}
print(DateTime.now().difference(start));
}