Created
April 16, 2024 06:05
-
-
Save matifdeveloper/de3c6d1140d2a26d32234d794a141333 to your computer and use it in GitHub Desktop.
Stop watch in dart
This file contains 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: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