Skip to content

Instantly share code, notes, and snippets.

@dickermoshe
Created December 19, 2024 00:23
Show Gist options
  • Save dickermoshe/6e40564abcc867e0c2711eee100708ec to your computer and use it in GitHub Desktop.
Save dickermoshe/6e40564abcc867e0c2711eee100708ec to your computer and use it in GitHub Desktop.
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