TF-495 Create a Benchmark object to calculate rendering time

This commit is contained in:
dab246
2022-04-19 14:58:32 +07:00
committed by Dat H. Pham
parent a7d71f02ff
commit 6c635bd388
2 changed files with 30 additions and 0 deletions
+1
View File
@@ -26,6 +26,7 @@ export 'presentation/utils/html_transformer/transform_configuration.dart';
export 'presentation/utils/html_transformer/dom/add_tooltip_link_transformers.dart';
export 'data/utils/device_manager.dart';
export 'utils/app_logger.dart';
export 'utils/benchmark.dart';
// Views
export 'presentation/views/text/slogan_builder.dart';
+29
View File
@@ -0,0 +1,29 @@
import 'package:core/utils/app_logger.dart';
class _Benchmark {
final Map<String, int> _starts = <String, int>{};
void start(dynamic id) {
final String benchId = id.toString();
if (_starts.containsKey(benchId)) {
log('_Benchmark::start(): Benchmark already have comparing with id=$benchId in time');
} else {
_starts[benchId] = DateTime.now().microsecondsSinceEpoch;
}
}
double end(dynamic id) {
final String benchId = id.toString();
if (!_starts.containsKey(benchId)) {
throw Exception('In Benchmark not placed comparing with id=$benchId');
}
final double diff = (DateTime.now().microsecondsSinceEpoch - _starts[benchId]!) / 1000;
final String info = '$benchId need ${diff}ms';
log('_Benchmark::end(): $info');
_starts.remove(benchId);
return diff;
}
}
final _Benchmark bench = _Benchmark();