mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 18:47:55 +00:00
[benchmarks] Remove unnecessary utf8.encode() as Uint8List
downcast
The return type of `utf8.encode()` was made more precise in [0] (from `List<int>` to `Uint8List`) [0] https://dart-review.googlesource.com/c/sdk/+/254903 TEST=ci Change-Id: I3e578ac8dc5f3f66396cb374e3dcadd989919518 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/321860 Commit-Queue: Martin Kustermann <kustermann@google.com> Reviewed-by: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
parent
70310b06d0
commit
4d4a922638
|
@ -42,7 +42,7 @@ Uint8List createSampleJson(final size) {
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
map['$i'] = list;
|
map['$i'] = list;
|
||||||
}
|
}
|
||||||
return utf8.encode(json.encode(map)) as Uint8List;
|
return utf8.encode(json.encode(map));
|
||||||
}
|
}
|
||||||
|
|
||||||
class JsonDecodeRequest {
|
class JsonDecodeRequest {
|
||||||
|
@ -113,7 +113,7 @@ class BenchmarkConfig {
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
final jsonString =
|
final jsonString =
|
||||||
File('benchmarks/IsolateJson/dart/sample.json').readAsStringSync();
|
File('benchmarks/IsolateJson/dart/sample.json').readAsStringSync();
|
||||||
final json250KB = utf8.encode(jsonString) as Uint8List; // 294356 bytes
|
final json250KB = utf8.encode(jsonString); // 294356 bytes
|
||||||
final decoded = json.decode(utf8.decode(json250KB));
|
final decoded = json.decode(utf8.decode(json250KB));
|
||||||
final decoded1MB = <dynamic, dynamic>{
|
final decoded1MB = <dynamic, dynamic>{
|
||||||
'1': decoded['1'],
|
'1': decoded['1'],
|
||||||
|
@ -121,14 +121,11 @@ Future<void> main() async {
|
||||||
'3': decoded['1'],
|
'3': decoded['1'],
|
||||||
'4': decoded['1'],
|
'4': decoded['1'],
|
||||||
};
|
};
|
||||||
final json1MB =
|
final json1MB = utf8.encode(json.encode(decoded1MB)); // 1177397 bytes
|
||||||
utf8.encode(json.encode(decoded1MB)) as Uint8List; // 1177397 bytes
|
|
||||||
decoded['1'] = (decoded['1'] as List).sublist(0, 200);
|
decoded['1'] = (decoded['1'] as List).sublist(0, 200);
|
||||||
final json100KB =
|
final json100KB = utf8.encode(json.encode(decoded)); // 104685 bytes
|
||||||
utf8.encode(json.encode(decoded)) as Uint8List; // 104685 bytes
|
|
||||||
decoded['1'] = (decoded['1'] as List).sublist(0, 100);
|
decoded['1'] = (decoded['1'] as List).sublist(0, 100);
|
||||||
final json50KB =
|
final json50KB = utf8.encode(json.encode(decoded)); // 51760 bytes
|
||||||
utf8.encode(json.encode(decoded)) as Uint8List; // 51760 bytes
|
|
||||||
|
|
||||||
final configs = <BenchmarkConfig>[
|
final configs = <BenchmarkConfig>[
|
||||||
BenchmarkConfig('50KB', json50KB),
|
BenchmarkConfig('50KB', json50KB),
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Utf8Decode extends BenchmarkBase {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void setup() {
|
void setup() {
|
||||||
final Uint8List data = utf8.encode(text) as Uint8List;
|
final Uint8List data = utf8.encode(text);
|
||||||
if (data.length != 10000) {
|
if (data.length != 10000) {
|
||||||
throw 'Expected input data of exactly 10000 bytes.';
|
throw 'Expected input data of exactly 10000 bytes.';
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ class Utf8Decode extends BenchmarkBase {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void setup() {
|
void setup() {
|
||||||
final Uint8List data = utf8.encode(text) as Uint8List;
|
final Uint8List data = utf8.encode(text);
|
||||||
if (data.length != 10000) {
|
if (data.length != 10000) {
|
||||||
throw 'Expected input data of exactly 10000 bytes.';
|
throw 'Expected input data of exactly 10000 bytes.';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue