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

Trending Topics

Online now

Members online
1,113
Guests online
8,204
Total visitors
9,317

Forum statistics

Threads
2,354,251
Posts
29,382,908
Members
1,079,393
Latest member
MasterLess
Back
Top