Skip to content

Instantly share code, notes, and snippets.

@hacker1024
Created March 22, 2021 02:43
Show Gist options
  • Select an option

  • Save hacker1024/8f54c8ee8cc381ce7b7a0e2be8767328 to your computer and use it in GitHub Desktop.

Select an option

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.
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');
}
@hacker1024

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment