Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sdk/core/Azure.Core/perf/Azure.Core.Perf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
<PackageReference Include="System.IO.Pipelines" />
</ItemGroup>
<ItemGroup>
<None Update="SerializationBenchmark\TestData\AvailabilitySetData.json">
<None Update="TestData\AvailabilitySetData.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SerializationBenchmark\TestData\ModelXml.xml">
<None Update="TestData\ModelXml.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SerializationBenchmark\TestData\ResourceProviderData.json">
<None Update="TestData\ResourceProviderData.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestData\JsonFormattedString.json">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Core.Tests.Public.ResourceManager.Resources;

namespace Azure.Core.Perf.RequestContents.ModelContent
{
public class LargeModel : ModelContentBenchmark<ResourceProviderData>
{
protected override string JsonFileName => "ResourceProviderData.json";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Core.Serialization;

namespace Azure.Core.Perf.RequestContents.ModelContent
{
public abstract class ModelContentBenchmark<T> : RequestContentBenchmark<IModelSerializable<T>> where T : class, IModelSerializable<T>
{
protected override RequestContent CreateRequestContent()
{
return RequestContent.Create(_model);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Core.Tests.Public.ResourceManager.Compute;

namespace Azure.Core.Perf.RequestContents.ModelContent
{
public class SmallModel : ModelContentBenchmark<AvailabilitySetData>
{
protected override string JsonFileName => "AvailabilitySetData.json";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Core.Tests.Public.ResourceManager.Resources;

namespace Azure.Core.Perf.RequestContents.ModelJsonContent
{
public class LargeModel : ModelJsonContentBenchmark<ResourceProviderData>
{
protected override string JsonFileName => "ResourceProviderData.json";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Core.Serialization;

namespace Azure.Core.Perf.RequestContents.ModelJsonContent
{
public abstract class ModelJsonContentBenchmark<T> : RequestContentBenchmark<IModelJsonSerializable<T>> where T : class, IModelJsonSerializable<T>
{
protected override RequestContent CreateRequestContent()
{
return RequestContent.Create(_model);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Core.Tests.Public.ResourceManager.Compute;

namespace Azure.Core.Perf.RequestContents.ModelJsonContent
{
public class SmallModel : ModelJsonContentBenchmark<AvailabilitySetData>
{
protected override string JsonFileName => "AvailabilitySetData.json";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.IO;
using System.Reflection;
using Azure.Core.Serialization;
using BenchmarkDotNet.Attributes;

namespace Azure.Core.Perf.RequestContents
{
public abstract class RequestContentBenchmark<T> where T : class
{
protected abstract string JsonFileName { get; }
protected abstract RequestContent CreateRequestContent();

protected T _model;
private RequestContent _serializedContent;
private MemoryStream _stream;

[GlobalSetup]
public void GlobalSetup()
{
string json = File.ReadAllText(Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, "TestData", JsonFileName));
Type modelType = typeof(T).GetGenericArguments()[0];
_model = ModelSerializer.Deserialize(BinaryData.FromString(json), modelType) as T;
_serializedContent = CreateRequestContent();
_serializedContent.TryComputeLength(out long length);
_stream = new MemoryStream((int)length);
}

[GlobalCleanup]
public void GlobalCleanup()
{
_serializedContent.Dispose();
_serializedContent = null;
}

[Benchmark]
public void Construct()
{
using RequestContent content = CreateRequestContent();
}

[Benchmark]
public long TryComputeLength()
{
using RequestContent content = CreateRequestContent();
content.TryComputeLength(out long length);
return length;
}

[Benchmark]
public void WriteTo()
{
_serializedContent.WriteTo(_stream, default);
_stream.Position = 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using System.Text.Json;
using Azure.Core.Tests.Public.ResourceManager.Compute;

namespace Azure.Core.Perf
namespace Azure.Core.Perf.Serializations
{
public class AvailabilitySetDataBenchmark : JsonSerializationBenchmark<AvailabilitySetData>
public class AvailabilitySetDataModel : JsonBenchmark<AvailabilitySetData>
{
protected override AvailabilitySetData Deserialize(JsonElement jsonElement)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
using BenchmarkDotNet.Reports;
using Perfolizer.Horology;

namespace Azure.Core.Perf
namespace Azure.Core.Perf.Serializations
{
internal class SerializationBenchmarkConfig : ManualConfig
internal class BenchmarkConfig : ManualConfig
{
public SerializationBenchmarkConfig()
public BenchmarkConfig()
{
SummaryStyle = SummaryStyle.Default
.WithTimeUnit(TimeUnit.Microsecond)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using BenchmarkDotNet.Attributes;

namespace Azure.Core.Perf
namespace Azure.Core.Perf.Serializations
{
public class BimodalRepro
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Licensed under the MIT License.

using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
Expand All @@ -13,18 +11,17 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;

namespace Azure.Core.Perf
namespace Azure.Core.Perf.Serializations
{
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
public abstract class JsonSerializationBenchmark<T> where T : class, IModelJsonSerializable<T>
public abstract class JsonBenchmark<T> where T : class, IModelJsonSerializable<T>
{
private string _json;
protected T _model;
protected Response _response;
protected ModelSerializerOptions _options;
private BinaryData _data;
private SequenceWriter _content;
private ReadOnlySequence<byte> _sequence;
private JsonDocument _jsonDocument;

protected abstract T Deserialize(JsonElement jsonElement);
Expand All @@ -40,7 +37,7 @@ public abstract class JsonSerializationBenchmark<T> where T : class, IModelJsonS
[GlobalSetup]
public void SetUp()
{
_json = File.ReadAllText(Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, "SerializationBenchmark", "TestData", JsonFileName));
_json = File.ReadAllText(Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, "TestData", JsonFileName));
_data = BinaryData.FromString(_json);
_model = ModelSerializer.Deserialize<T>(_data);
_response = new MockResponse(200);
Expand All @@ -50,7 +47,6 @@ public void SetUp()
using Utf8JsonWriter writer = new Utf8JsonWriter(_content);
_model.Serialize(writer, new ModelSerializerOptions());
writer.Flush();
_sequence = _content.GetReadOnlySequence();
_jsonDocument = JsonDocument.Parse(_json);
}

Expand Down Expand Up @@ -176,20 +172,6 @@ public T Deserialize_Utf8JsonReaderFromBinaryData()
return _model.Deserialize(ref reader, _options);
}

[Benchmark]
[BenchmarkCategory("JsonDocument")]
public ReadOnlySequence<byte> GetSequence()
{
return _content.GetReadOnlySequence();
}

[Benchmark]
[BenchmarkCategory("JsonDocument")]
public void JsonDocumentFromSequence()
{
using var doc = JsonDocument.Parse(_sequence);
}

[Benchmark]
[BenchmarkCategory("JsonDocument")]
public void JsonDocumentFromReader()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Xml;
using System.Xml.Linq;
using Azure.Core.Tests.Public.ModelSerializationTests.Models;

namespace Azure.Core.Perf
namespace Azure.Core.Perf.Serializations
{
public class ModelXmlBenchmark : XmlSerializationBenchmark<ModelXml>
public class ModelXmlModel : XmlBenchmark<ModelXml>
{
protected override string XmlFileName => "ModelXml.xml";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Text.Json;
using Azure.Core.Tests.Public.ResourceManager.Resources;
using BenchmarkDotNet.Attributes;

namespace Azure.Core.Perf
namespace Azure.Core.Perf.Serializations
{
[Config(typeof(SerializationBenchmarkConfig))]
public class ResourceProviderDataBenchmark : JsonSerializationBenchmark<ResourceProviderData>
[Config(typeof(BenchmarkConfig))]
public class ResourceProviderDataModel : JsonBenchmark<ResourceProviderData>
{
protected override string JsonFileName => "ResourceProviderData.json";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;

namespace Azure.Core.Perf
namespace Azure.Core.Perf.Serializations
{
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
public abstract class XmlSerializationBenchmark<T> where T : class, IModelSerializable<T>
public abstract class XmlBenchmark<T> where T : class, IModelSerializable<T>
{
private string _xml;
protected T _model;
Expand All @@ -37,7 +37,7 @@ public abstract class XmlSerializationBenchmark<T> where T : class, IModelSerial
[GlobalSetup]
public void SetUp()
{
_xml = File.ReadAllText(Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, "SerializationBenchmark", "TestData", XmlFileName));
_xml = File.ReadAllText(Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, "TestData", XmlFileName));
_data = BinaryData.FromString(_xml);
_model = ModelSerializer.Deserialize<T>(_data);
_response = new MockResponse(200);
Expand Down
Loading