如何在Flutter中跟踪功能?

问题描述 投票:0回答:3

我有习惯跟踪我的功能运行多长时间,在react native我可以使用console.timereact-native-console-time-polyfill

myFunction(){
  console.time("Func Foo")
  //any logic here
  console.timeEnd("Func Foo")
}

我怎么能用Flutter做到这一点?

timer dart flutter
3个回答
0
投票

检查此URL。

您可以在flutter中获取调试的所有信息

https://flutter.dev/docs/testing/debugging

它会对你有所帮助。


0
投票

也许你可以尝试这个..

void main() async {
  var dateTimeNow = DateTime.now();

  await someExecution(); // call your function here.

  var dateTimeAfterExecution = DateTime.now();

  var difference = dateTimeAfterExecution.difference(dateTimeNow);
  print(difference.inMilliseconds);
}

0
投票

试试这个

myFunction(){
  var oldTime = DateTime.now().millisecondsSinceEpoch;
  //any logic here

  // total time taken to run the logic would be
  print("time = ${DateTime.now().millisecondsSinceEpoch - oldTime} ms");
}
© www.soinside.com 2019 - 2024. All rights reserved.