Created
March 22, 2021 02:43
-
-
Save hacker1024/8f54c8ee8cc381ce7b7a0e2be8767328 to your computer and use it in GitHub Desktop.
The most efficient way to initialize an integer with a value of 10 in Dart.
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
| import 'dart:math'; | |
| /// Thanks to https://www.reddit.com/r/ProgrammerHumor/comments/m9r3vz/efficiency/ for the inspiration | |
| void main() { | |
| final random = Random(); | |
| final stopwatch = Stopwatch()..start(); | |
| int x; | |
| do { | |
| x = random.nextInt(1 << 31); | |
| } while (x != 10); | |
| stopwatch.stop(); | |
| print('${stopwatch.elapsedMilliseconds / Duration.millisecondsPerSecond}s'); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://dartpad.dev/8f54c8ee8cc381ce7b7a0e2be8767328?null_safety=true