I am trying to understand async/await but I discovered this.
The two code below only differ from the keyword async
void main() {
asyncAwait();
}
void asyncAwait() {
int i = 0;
DateTime now = DateTime.now();
print(" Now ");
while (i++ < 10000000000);
DateTime after = DateTime.now();
print("Done in ${after.difference(now)}");
}
Now Done in 0:00:09.222742
void main() {
asyncAwait();
}
void asyncAwait() async {
int i = 0;
DateTime now = DateTime.now();
print(" Now ");
while (i++ < 10000000000);
DateTime after = DateTime.now();
print("Done in ${after.difference(now)}");
}
Now Done in 0:00:30.555924
One is at least 3 times faster than the other. I am looking for an explanation at the compiler level but I could not find any documentation about so.
I run it with this command with dart 2.13.0
dart main.dart
If you don't see a huge difference, chance 10000000000 to 100000000000