Files
sdk/pkg/front_end/test/dill_round_trip_test.dart
T
Johnni Winther 357e83e44d [cfe] Rename incremental_load/initialize_from_dill(_suite) to incremental(_suite)
Change-Id: I747151249330ed3c9c1026289be52d5ca0dca891
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/185600
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2021-02-19 08:41:07 +00:00

62 lines
2.0 KiB
Dart

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.9
import 'package:front_end/src/fasta/kernel/utils.dart' show serializeComponent;
import 'package:kernel/ast.dart' show Component;
import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;
import 'package:kernel/target/targets.dart' show NoneTarget, TargetFlags;
import 'incremental_suite.dart'
show checkIsEqual, getOptions, normalCompilePlain;
main() async {
final Uri dart2jsUrl = Uri.base.resolve("pkg/compiler/bin/dart2js.dart");
Stopwatch stopwatch = new Stopwatch()..start();
Component compiledComponent = await normalCompilePlain(dart2jsUrl,
options: getOptions()
..target = new NoneTarget(new TargetFlags())
..omitPlatform = false);
print("Compiled dart2js in ${stopwatch.elapsedMilliseconds} ms");
stopwatch.reset();
List<int> bytes = serializeComponent(compiledComponent);
print("Serialized dart2js in ${stopwatch.elapsedMilliseconds} ms");
print("Output is ${bytes.length} bytes long.");
print("");
stopwatch.reset();
print("Round-tripping with lazy disabled");
roundTrip(
new BinaryBuilder(bytes,
disableLazyReading: true, disableLazyClassReading: true),
bytes);
print("Round-tripping with lazy enabled");
roundTrip(
new BinaryBuilder(bytes,
disableLazyReading: false, disableLazyClassReading: false),
bytes);
print("OK");
}
void roundTrip(BinaryBuilder binaryBuilder, List<int> bytes) {
Stopwatch stopwatch = new Stopwatch()..start();
Component c = new Component();
binaryBuilder.readComponent(c);
List<int> bytesRoundTripped = serializeComponent(c);
print("Loaded and serialized in ${stopwatch.elapsedMilliseconds} ms");
stopwatch.reset();
checkIsEqual(bytes, bytesRoundTripped);
print("Checked equal in ${stopwatch.elapsedMilliseconds} ms");
stopwatch.reset();
print("");
}