무기/다트

<다트> Stopwatch - 함수 호출 완료 시간 검토

디벅잉 2023. 4. 8. 21:58
728x90

 

🧭

 

함수 호출 시간

개발을 하다보면 함수 호출이 완료되기 까지 시간이 얼마나 걸리는지 확인해야 할 필요가 있거나 확인하고 싶을 때가 있습니다.

 

Stopwatch

이럴 때 사용하는 클래스가 Stopwatch입니다.

바로 사용해 보겠습니다.

void yourFunction() {
  final stopwatch = Stopwatch()..start();

  // something to do...

  stopwatch.stop();
  print('Microseconds:${stopwatch.elapsedMicroseconds}');
}

함수 시작시 stopwatch를 start하고, 종료 직전 stop하면 함수 안에서 시간이 얼마나 소요되는지 확인할 수 있습니다.

 

📌

 

https://api.flutter.dev/flutter/dart-core/Stopwatch-class.html

 

Stopwatch class - dart:core library - Dart API

A stopwatch which measures time while it's running. A stopwatch is either running or stopped. It measures the elapsed time that passes while the stopwatch is running. When a stopwatch is initially created, it is stopped and has measured no elapsed time. Th

api.flutter.dev

 

728x90