58

我制作了一些涉及解析 html 的片段,并想知道代码是否运行缓慢,这可行吗?

4

3 回答 3

123

您可以使用秒表来测量执行时间:

Stopwatch stopwatch = new Stopwatch()..start();
doSomething();
print('doSomething() executed in ${stopwatch.elapsed}');

飞镖 2:

  • 类型推断
  • 可选的new
final stopwatch = Stopwatch()..start();
doSomething();
print('doSomething() executed in ${stopwatch.elapsed}');
于 2013-06-06T06:36:02.683 回答
8

如果您在网络上,您可以获得一个高分辨率计时器:

num time = window.performance.now();

来自http://api.dartlang.org/docs/releases/latest/dart_html/Performance.html#now

于 2013-06-07T01:00:52.210 回答
4

在配置文件模式下使用 devtools 以获得最佳结果

import 'dart:developer';

Timeline.startSync('interesting function');
// iWonderHowLongThisTakes();
Timeline.finishSync();

https://flutter.dev/docs/testing/code-debugging#tracing-dart-code-performance

于 2020-06-23T01:50:09.550 回答