mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 12:30:03 +00:00
c3ddc5c374
The existing EventLoopLatencyJson benchmark exercises the *worst case scenario*: A background isolate is stressing the GC where the working memory set does not fit into new space. This causes scavenges to copy the entire newspace either into the to-space or promote it to old space. The benchmark in this CL is similar to EventLoopLatencyJson, but it's working memory set is significantly lower than new space, therefore not exercising this worst case scenario (this represents the most common scenario, which we would expect for compute() function in flutter) (Due to difficulty sharing code between benchmarks, this CL adds similar code as EventLoopLatencyJson) Issue https://github.com/dart-lang/sdk/issues/36097 Change-Id: I385a620ba8900082f8ca5fb9080fc23d95112e83 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169100 Reviewed-by: Alexander Aprelev <aam@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
50 lines
1.2 KiB
Dart
50 lines
1.2 KiB
Dart
// Copyright (c) 2020, 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 'dart:math';
|
|
import 'dart:convert';
|
|
|
|
class JsonRoundTripBenchmark {
|
|
void run() {
|
|
final res = json.decode(jsonData);
|
|
final out = json.encode(res);
|
|
if (out[0] != jsonData[0]) {
|
|
throw 'json conversion error';
|
|
}
|
|
}
|
|
}
|
|
|
|
// Builds around 350 KB of json data - small enough so the decoded object graph
|
|
// fits into new space.
|
|
final String jsonData = () {
|
|
final rnd = Random(42);
|
|
dynamic buildTree(int depth) {
|
|
final int coin = rnd.nextInt(1000);
|
|
if (depth == 0) {
|
|
if (coin % 2 == 0) return coin;
|
|
return 'foo-$coin';
|
|
}
|
|
|
|
if (coin % 2 == 0) {
|
|
final map = <String, dynamic>{};
|
|
final int length = rnd.nextInt(19);
|
|
for (int i = 0; i < length; ++i) {
|
|
map['bar-$i'] = buildTree(depth - 1);
|
|
}
|
|
return map;
|
|
} else {
|
|
final list = <dynamic>[];
|
|
final int length = rnd.nextInt(18);
|
|
for (int i = 0; i < length; ++i) {
|
|
list.add(buildTree(depth - 1));
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
|
|
return json.encode({'data': buildTree(5)});
|
|
}();
|