benckmark_test.dart
1.6 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
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:get/state_manager.dart';
int times = 3;
int get last => times - 1;
Future<String> valueNotifier() {
final c = Completer<String>();
final value = ValueNotifier<int>(0);
final timer = Stopwatch();
timer.start();
value.addListener(() {
if (last == value.value) {
timer.stop();
c.complete("""${value.value} item value notifier
objs time: ${timer.elapsedMicroseconds}ms""");
}
});
for (var i = 0; i < times; i++) {
value.value = i;
}
return c.future;
}
Future<String> getValue() {
final c = Completer<String>();
final value = Value<int>(0);
final timer = Stopwatch();
timer.start();
value.addListener(() {
if (last == value.value) {
timer.stop();
c.complete("""${value.value} item get value objs
time: ${timer.elapsedMicroseconds}ms""");
}
});
for (var i = 0; i < times; i++) {
value.value = i;
}
return c.future;
}
Future<String> getStream() {
final c = Completer<String>();
final value = StreamController<int>();
final timer = Stopwatch();
timer.start();
value.stream.listen((v) {
if (last == v) {
timer.stop();
c.complete("$v item stream objs time: ${timer.elapsedMicroseconds}ms");
}
});
for (var i = 0; i < times; i++) {
value.add(i);
}
return c.future;
}
void main() async {
print(await getValue());
print(await valueNotifier());
print(await getStream());
times = 30000;
print(await getValue());
print(await valueNotifier());
print(await getStream());
}
typedef VoidCallback = void Function();