Skip to content

Instantly share code, notes, and snippets.

@matifdeveloper
Created April 16, 2024 06:05
Show Gist options
  • Save matifdeveloper/de3c6d1140d2a26d32234d794a141333 to your computer and use it in GitHub Desktop.
Save matifdeveloper/de3c6d1140d2a26d32234d794a141333 to your computer and use it in GitHub Desktop.
Stop watch in dart
import 'dart:async';
void main() async {
var stopWatch = Stopwatch();
stopWatch.start();
await Future.delayed(const Duration(seconds: 2), () {});
stopWatch.stop();
// Retrieve milliseconds from the Duration object
var elapsedMilliseconds = stopWatch.elapsedMilliseconds;
print('Elapsed time in milliseconds: $elapsedMilliseconds');
// or just get duration in seconds
var elapsedSeconds = stopWatch.elapsed.inSeconds;
print('Elapsed time in seconds: $elapsedSeconds');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment