Update tooling benchmarks to use new JsonDataConvert APIs

This commit is contained in:
Dustin Campbell 2024-11-18 17:03:27 -08:00
Родитель 18802f3064
Коммит 9bbbe46332
3 изменённых файлов: 7 добавлений и 31 удалений

Просмотреть файл

@ -2,7 +2,6 @@
// Licensed under the MIT license. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.IO;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.AspNetCore.Razor.Serialization.Json;
@ -24,20 +23,8 @@ internal static class CommonResources
public static readonly RazorProjectInfo TelerikProjectInfo = LoadProjectInfo(TelerikProjectInfoJsonBytes);
private static ImmutableArray<TagHelperDescriptor> LoadTagHelpers(byte[] bytes)
{
using var stream = new MemoryStream(bytes);
using var reader = new StreamReader(stream);
return JsonDataConvert.DeserializeData(reader,
static r => r.ReadImmutableArray(ObjectReaders.ReadTagHelper)).NullToEmpty();
}
=> JsonDataConvert.DeserializeTagHelperArray(bytes);
private static RazorProjectInfo LoadProjectInfo(byte[] bytes)
{
using var stream = new MemoryStream(bytes);
using var reader = new StreamReader(stream);
return JsonDataConvert.DeserializeData(reader,
static r => r.ReadNonNullObject(ObjectReaders.ReadProjectInfoFromProperties));
}
=> JsonDataConvert.DeserializeProjectInfo(bytes);
}

Просмотреть файл

@ -44,15 +44,10 @@ public class RazorProjectInfoSerializationBenchmark
};
private static RazorProjectInfo DeserializeProjectInfo_Json(TextReader reader)
{
return JsonDataConvert.DeserializeData(reader,
static r => r.ReadNonNullObject(ObjectReaders.ReadProjectInfoFromProperties));
}
=> JsonDataConvert.DeserializeProjectInfo(reader);
private static void SerializeProjectInfo_Json(TextWriter writer, RazorProjectInfo projectInfo)
{
JsonDataConvert.SerializeObject(writer, projectInfo, ObjectWriters.WriteProperties);
}
=> JsonDataConvert.Serialize(projectInfo, writer);
[Benchmark(Description = "Serialize RazorProjectInfo (JSON)")]
public void Serialize_Json()
@ -100,7 +95,7 @@ public class RazorProjectInfoSerializationBenchmark
}
}
[GlobalSetup(Targets = new[] { nameof(Serialize_MessagePack), nameof(Deserialize_MessagePack), nameof(RoundTrip_MessagePack) })]
[GlobalSetup(Targets = [nameof(Serialize_MessagePack), nameof(Deserialize_MessagePack), nameof(RoundTrip_MessagePack)])]
public void GlobalSetup_MessagePack()
{
_buffer = new ArrayBufferWriter<byte>(initialCapacity: 1024 * 1024);

Просмотреть файл

@ -46,16 +46,10 @@ public class TagHelperSerializationBenchmark
};
private static ImmutableArray<TagHelperDescriptor> DeserializeTagHelpers_Json(TextReader reader)
{
return JsonDataConvert.DeserializeData(reader,
static r => r.ReadImmutableArray(ObjectReaders.ReadTagHelper));
}
=> JsonDataConvert.DeserializeTagHelperArray(reader);
private static void SerializeTagHelpers(TextWriter writer, ImmutableArray<TagHelperDescriptor> tagHelpers)
{
JsonDataConvert.SerializeData(writer,
w => w.WriteArray(tagHelpers, ObjectWriters.Write));
}
=> JsonDataConvert.Serialize(tagHelpers, writer);
[Benchmark(Description = "Serialize Tag Helpers (JSON)")]
public void Serialize_Json()