🔒 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
  • 665
    Views
  • 1
    Participants
Last reply from:
Katipunero-

Online now

Members online
1,017
Guests online
893
Total visitors
1,910

Forum statistics

Threads
2,276,230
Posts
28,968,483
Members
1,231,174
Latest member
jpryno
Back
Top