Created
December 19, 2024 00:23
-
-
Save dickermoshe/6e40564abcc867e0c2711eee100708ec to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Foo { | |
int bar; | |
Foo(this.bar); | |
} | |
void main() { | |
var data = List.generate(10_000_000, (i) => Foo(i)); | |
// Imutable | |
final t1 = DateTime.now(); | |
data = [for (final i in data) Foo(i.bar + 1)]; | |
// Mutate | |
final t2 = DateTime.now(); | |
for (final i in data) { | |
i.bar += 1; | |
} | |
final t3 = DateTime.now(); | |
print("Copy took ${t2.difference(t1).inMilliseconds}ms"); | |
print("Mutate took ${t3.difference(t2).inMilliseconds}ms"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment