【发布时间】:2013-06-06 06:30:30
【问题描述】:
我做了一些涉及解析html的sn-p,想知道代码是否运行缓慢,这可行吗?
【问题讨论】:
标签: dart
我做了一些涉及解析html的sn-p,想知道代码是否运行缓慢,这可行吗?
【问题讨论】:
标签: dart
您可以使用Stopwatch 来测量执行时间:
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}');
【讨论】:
stopwatch.stop() 吗?
elapsed 返回一个Duration,您可以调用inMilliseconds、inSeconds 等来获得首选单位。
如果你在网上,你可以得到一个高分辨率的计时器:
num time = window.performance.now();
来自http://api.dartlang.org/docs/releases/latest/dart_html/Performance.html#now
【讨论】:
在配置文件模式下使用 devtools 以获得最佳效果
import 'dart:developer';
Timeline.startSync('interesting function');
// iWonderHowLongThisTakes();
Timeline.finishSync();
https://flutter.dev/docs/testing/code-debugging#tracing-dart-code-performance
【讨论】: