🔒 Closed [dart] Measure execution time of an async function

Status
Not open for further replies.

Katipunero-

Honorary Poster
Code:
void main() async {
  print('Started.');
  Stopwatch stopwatch =  Stopwatch()..start();
  String x = await helloAsync();
  print(x);
  print('helloAsync() executed in ${stopwatch.elapsed}');
 
}
Future<String> helloAsync() async{
   await Future.delayed(Duration(seconds:5));
   return 'Message from Future.';
}

Output:
Started.
Message from Future.
helloAsync() executed in 0:00:05.016700
 
Status
Not open for further replies.

About this Thread

  • 0
    Replies
  • 668
    Views
  • 1
    Participants
Last reply from:
Katipunero-

Trending Topics

Online now

Members online
463
Guests online
965
Total visitors
1,428

Forum statistics

Threads
2,286,945
Posts
29,041,378
Members
1,217,282
Latest member
Andreew00012
Back
Top