LCOV - code coverage report
Current view: top level - lib/src/utils - run_benchmarked.dart (source / functions) Coverage Total Hit
Test: merged.info Lines: 22.2 % 9 2
Test Date: 2025-10-13 02:23:18 Functions: - 0 0

            Line data    Source code
       1              : /*
       2              :  *   Famedly Matrix SDK
       3              :  *   Copyright (C) 2019, 2020 Famedly GmbH
       4              :  *
       5              :  *   This program is free software: you can redistribute it and/or modify
       6              :  *   it under the terms of the GNU Affero General Public License as
       7              :  *   published by the Free Software Foundation, either version 3 of the
       8              :  *   License, or (at your option) any later version.
       9              :  *
      10              :  *   This program is distributed in the hope that it will be useful,
      11              :  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
      12              :  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      13              :  *   GNU Affero General Public License for more details.
      14              :  *
      15              :  *   You should have received a copy of the GNU Affero General Public License
      16              :  *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
      17              :  */
      18              : 
      19              : import 'package:matrix/matrix.dart';
      20              : 
      21              : var kEnableMatrixSdkBenchmarks = false;
      22              : 
      23              : /// Calculates some benchmarks for this function. Give it a [name] and a [func]
      24              : /// to call and it will calculate the needed milliseconds. Give it an optional
      25              : /// [itemCount] to let it also calculate the needed milliseconds per item.
      26           41 : Future<T> runBenchmarked<T>(
      27              :   String name,
      28              :   Future<T> Function() func, [
      29              :   int? itemCount,
      30              : ]) async {
      31              :   if (!kEnableMatrixSdkBenchmarks) {
      32           41 :     return func();
      33              :   }
      34            0 :   final start = DateTime.now();
      35            0 :   final result = await func();
      36              :   final milliseconds =
      37            0 :       DateTime.now().millisecondsSinceEpoch - start.millisecondsSinceEpoch;
      38            0 :   var message = 'Benchmark: $name -> $milliseconds ms';
      39              :   if (itemCount != null) {
      40            0 :     message +=
      41            0 :         ' ($itemCount items, ${itemCount > 0 ? milliseconds / itemCount : milliseconds} ms/item)';
      42              :   }
      43            0 :   Logs().d(message);
      44              :   return result;
      45              : }
        

Generated by: LCOV version 2.0-1