Skip to content

Instantly share code, notes, and snippets.

@rafalbednarczuk
Last active December 23, 2020 18:53
Show Gist options
  • Save rafalbednarczuk/654a9751f166e1c550a6c04b034dbd19 to your computer and use it in GitHub Desktop.
Save rafalbednarczuk/654a9751f166e1c550a6c04b034dbd19 to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
void main() async {
Future<void> _notifierTest() async {
await Future.delayed(Duration(seconds: 1));
final iNotifier = ValueNotifier<int>(null);
var notifierCounter = 0;
final date = DateTime.now();
iNotifier.addListener(() {
notifierCounter++;
if (notifierCounter == 100) {
print("iNotifier:${DateTime.now().difference(date).inMilliseconds/100}ms");
}
});
for (var i = 0; i < 100; i++) {
iNotifier.value = 10;
iNotifier.notifyListeners();
}
}
Future<void> _streamTest() async {
await Future.delayed(Duration(seconds: 1));
final streamController = StreamController();
var streamCounter = 0;
final date = DateTime.now();
streamController.stream.listen((value) {
streamCounter++;
if (streamCounter == 100) {
print("stream:${DateTime.now().difference(date).inMilliseconds/100}ms");
streamController.close();
}
});
for (var i = 0; i < 100; i++) {
streamController.add(10);
}
}
await _notifierTest();
await _streamTest();
await _notifierTest();
await _streamTest();
await _notifierTest();
await _streamTest();
await _notifierTest();
await _streamTest();
await Future.delayed(Duration(seconds: 100));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment