Skip to content

Instantly share code, notes, and snippets.

@riscait
Last active September 28, 2023 06:33
Show Gist options
  • Save riscait/7e5e554963b98671c87abc10cb184361 to your computer and use it in GitHub Desktop.
Save riscait/7e5e554963b98671c87abc10cb184361 to your computer and use it in GitHub Desktop.
Collection for vs. map

Collection for vs. map

Created with <3 with dartpad.dev.

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