Created with <3 with dartpad.dev.
Last active
September 28, 2023 06:33
-
-
Save riscait/7e5e554963b98671c87abc10cb184361 to your computer and use it in GitHub Desktop.
Collection for vs. map
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
void main() { | |
final stopwatch = Stopwatch(); | |
() { | |
stopwatch.start(); | |
final sut = List.generate(100000, (index) => index * index); | |
[for (final s in sut) s.toString()]; | |
stopwatch.stop(); | |
print('for time: ${stopwatch.elapsedMilliseconds} ms'); | |
}(); | |
stopwatch.reset(); | |
() { | |
stopwatch.start(); | |
final sut = List.generate(100000, (index) => index * index); | |
sut.map((e) => e.toString()).toList(); | |
stopwatch.stop(); | |
print('map time: ${stopwatch.elapsedMilliseconds} ms'); | |
}(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment