"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/dev/benchmarks/microbenchmarks/lib/geometry/curves_bench.dart" (13 Nov 2020, 1641 Bytes) of package /linux/misc/flutter-1.22.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2014 The Flutter Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style license that can be
    3 // found in the LICENSE file.
    4 
    5 import 'dart:ui';
    6 import 'package:flutter/animation.dart';
    7 
    8 import '../common.dart';
    9 
   10 const int _kNumIters = 10000;
   11 
   12 void _testCurve(Curve curve, {String name, String description, BenchmarkResultPrinter printer}) {
   13   final Stopwatch watch = Stopwatch();
   14   print('$description benchmark...');
   15   watch.start();
   16   for (int i = 0; i < _kNumIters; i += 1) {
   17     final double t = i / _kNumIters.toDouble();
   18     curve.transform(t);
   19   }
   20   watch.stop();
   21 
   22   printer.addResult(
   23     description: description,
   24     value: watch.elapsedMicroseconds / _kNumIters,
   25     unit: '┬Ás per iteration',
   26     name: name,
   27   );
   28 }
   29 
   30 void main() {
   31   assert(false, "Don't run benchmarks in checked mode! Use 'flutter run --release'.");
   32   final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
   33   _testCurve(
   34     const Cubic(0.0, 0.25, 0.5, 1.0),
   35     name: 'cubic_animation_transform_iteration',
   36     description: 'Cubic animation transform',
   37     printer: printer,
   38   );
   39 
   40   final CatmullRomCurve catmullRomCurve = CatmullRomCurve(const <Offset>[
   41     Offset(0.09, 0.99),
   42     Offset(0.21, 0.01),
   43     Offset(0.28, 0.99),
   44     Offset(0.38, -0.00),
   45     Offset(0.43, 0.99),
   46     Offset(0.54, -0.01),
   47     Offset(0.59, 0.98),
   48     Offset(0.70, 0.04),
   49     Offset(0.78, 0.98),
   50     Offset(0.88, -0.00),
   51   ], tension: 0.00);
   52   _testCurve(
   53     catmullRomCurve,
   54     name: 'catmullrom_transform_iteration',
   55     description: 'CatmullRomCurve animation transform',
   56     printer: printer,
   57   );
   58 
   59   printer.printToStdout();
   60 }