Skip to content

Commit

Permalink
Fixed smoke test added more perf tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Willey committed May 15, 2020
1 parent 5adc575 commit 708cc2b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ internal static MemoryStream ToStream(
return new MemoryStream(resultAsArray.Array, resultAsArray.Offset, resultAsArray.Count, writable: false, publiclyVisible: true);
}

internal static IEnumerable<T> GetResources<T>(
internal static IReadOnlyList<T> GetResources<T>(
IReadOnlyList<CosmosElement> cosmosArray,
CosmosSerializerCore serializerCore)
{
Expand All @@ -232,15 +232,15 @@ internal static IEnumerable<T> GetResources<T>(

if (typeof(CosmosElement).IsAssignableFrom(typeof(T)))
{
return cosmosArray.Cast<T>();
return cosmosArray.Cast<T>().ToList();
}

return CosmosElementSerializer.GetResourcesHelper<T>(
cosmosArray,
serializerCore);
}

private static IEnumerable<T> GetResourcesHelper<T>(
private static IReadOnlyList<T> GetResourcesHelper<T>(
IReadOnlyList<CosmosElement> cosmosArray,
CosmosSerializerCore serializerCore)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private class FailedUserSerializer : CosmosSerializer
public override T FromStream<T>(Stream stream)
{
// Only let changes serialization pass through
if (typeof(T) == typeof(TestClass))
if (typeof(T) == typeof(List<TestClass>))
{
return this.cosmosSerializer.FromStream<T>(stream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
using System.Text;
using BenchmarkDotNet.Attributes;
using Microsoft.Azure.Cosmos.CosmosElements;
using Microsoft.Azure.Cosmos.Json;
using Microsoft.Azure.Cosmos.Json.Interop;
using Microsoft.Azure.Cosmos.Serializer;
using Microsoft.Azure.Cosmos.Tests.Poco;
using Newtonsoft.Json;

[MemoryDiagnoser]
Expand All @@ -31,7 +28,7 @@ public class ToDoActivity

public ToDoActivity[] children { get; set; }

public override bool Equals(Object obj)
public override bool Equals(object obj)
{
ToDoActivity input = obj as ToDoActivity;
if (input == null)
Expand Down Expand Up @@ -110,23 +107,39 @@ public ReadFeedBenchmark()
}

[Benchmark]
public void ByteFindArrayParsingJson()
public void ByteParsingToFindJsonArray()
{
using (MemoryStream ms = new MemoryStream(this.payloadBytes))
{
using (MemoryStream memoryStream = CosmosFeedResponseSerializer.GetStreamWithoutServiceEnvelope(
ms))
long length = ms.Length;
using (MemoryStream memoryStream = CosmosFeedResponseSerializer.GetStreamWithoutServiceEnvelope(ms))
{
if (ms.Length == memoryStream.Length)
if (length == memoryStream.Length)
{
throw new Exception();
}
}
}
}
}

[Benchmark]
public void ByteParsingToFindJsonArrayWithSeriliazation()
{
using (MemoryStream ms = new MemoryStream(this.payloadBytes))
{
IReadOnlyList<ToDoActivity> results = CosmosFeedResponseSerializer.FromFeedResponseStream<ToDoActivity>(
this.serializerCore,
ms);

if (results.Count != 1000)
{
throw new Exception();
}
}
}

[Benchmark]
public void CosmosElements()
public void CosmosElementsToFindArray()
{
using (MemoryStream ms = new MemoryStream(this.payloadBytes))
{
Expand All @@ -135,7 +148,7 @@ public void CosmosElements()
Documents.ResourceType.Document,
null);

using(MemoryStream memoryStream = CosmosElementSerializer.ElementToMemoryStream(
using (MemoryStream memoryStream = CosmosElementSerializer.ElementToMemoryStream(
array,
null))
{
Expand All @@ -146,5 +159,26 @@ public void CosmosElements()
}
}
}

[Benchmark]
public void CosmosElementsToFindArrayWithSerialization()
{
using (MemoryStream ms = new MemoryStream(this.payloadBytes))
{
CosmosArray array = CosmosElementSerializer.ToCosmosElements(
ms,
Documents.ResourceType.Document,
null);

IReadOnlyList<ToDoActivity> results = CosmosElementSerializer.GetResources<ToDoActivity>(
array,
this.serializerCore);

if (results.Count != 1000)
{
throw new Exception();
}
}
}
}
}

0 comments on commit 708cc2b

Please sign in to comment.