Created
January 31, 2021 13:51
-
-
Save alphamikle/254d5f112c126bf75c2ff1048201726f to your computer and use it in GitHub Desktop.
Loading items with compute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> loadItemsWithComputed() async { | |
_startFpsMeter(); | |
isLoading = true; | |
notifyListeners(); | |
List<Item> computedItems; | |
/// There were two variants of execution | |
/// Each set of 5 concurrent requests, run sequentially, | |
/// ran in compute function | |
if (true) { | |
for (int i = 0; i < 10; i++) { | |
bench.startTimer('Load items in computed'); | |
computedItems = await compute<dynamic, List<Item>>(_loadItemsWithComputed, null); | |
final double diff = bench.endTimer('Load items in computed'); | |
requestDurations.add(diff); | |
} | |
/// The second option is all 10 requests of 5 in one compute function | |
} else { | |
bench.startTimer('Load items in computed'); | |
computedItems = await compute<dynamic, List<Item>>(_loadAllItemsWithComputed, null); | |
final double diff = bench.endTimer('Load items in computed'); | |
requestDurations.add(diff); | |
} | |
items.clear(); | |
items.addAll(computedItems); | |
isLoading = false; | |
notifyListeners(); | |
_stopFpsMeter(); | |
requestDurations.clear(); | |
} | |
Future<List<Item>> _loadItemsWithComputed([dynamic _]) async { | |
return makeManyRequests(5); | |
} | |
Future<List<Item>> _loadAllItemsWithComputed([dynamic _]) async { | |
List<Item> items; | |
for (int i = 0; i < 10; i++) { | |
items = await makeManyRequests(5); | |
} | |
return items; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment