Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added NetDataContractSerializer to benechmarks #4

Merged
merged 3 commits into from

2 participants

@dnauck

Hello Demis,

here're the required changes to get also results for the NetDataContractSerializer.
Now we can see how much impact the added type information have.

Kind regards,
Daniel

@mythz mythz merged commit c141543 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
8 src/Northwind.Benchmarks/Northwind.Benchmarks.sln
@@ -9,8 +9,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Northwind.Common", "Northwi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Northwind.Benchmarks.Console", "Northwind.Benchmarks.Console\Northwind.Benchmarks.Console.csproj", "{D5681EFB-0FCE-4E55-910B-F4620CFECBD2}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.Text", "..\..\..\ServiceStack.Text\src\ServiceStack.Text\ServiceStack.Text.csproj", "{579B3FDB-CDAD-44E1-8417-885C38E49A0E}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -42,12 +40,6 @@ Global
{D5681EFB-0FCE-4E55-910B-F4620CFECBD2}.MonoTouch|Any CPU.Build.0 = Release|Any CPU
{D5681EFB-0FCE-4E55-910B-F4620CFECBD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5681EFB-0FCE-4E55-910B-F4620CFECBD2}.Release|Any CPU.Build.0 = Release|Any CPU
- {579B3FDB-CDAD-44E1-8417-885C38E49A0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {579B3FDB-CDAD-44E1-8417-885C38E49A0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {579B3FDB-CDAD-44E1-8417-885C38E49A0E}.MonoTouch|Any CPU.ActiveCfg = MonoTouch|Any CPU
- {579B3FDB-CDAD-44E1-8417-885C38E49A0E}.MonoTouch|Any CPU.Build.0 = MonoTouch|Any CPU
- {579B3FDB-CDAD-44E1-8417-885C38E49A0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {579B3FDB-CDAD-44E1-8417-885C38E49A0E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
7 src/Northwind.Benchmarks/Northwind.Benchmarks/Northwind.Benchmarks.csproj
@@ -88,6 +88,9 @@
<Reference Include="ServiceStack.Interfaces">
<HintPath>..\Lib\ServiceStack.Interfaces.dll</HintPath>
</Reference>
+ <Reference Include="ServiceStack.Text">
+ <HintPath>..\Lib\ServiceStack.Text.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -121,10 +124,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\..\..\..\ServiceStack.Text\src\ServiceStack.Text\ServiceStack.Text.csproj">
- <Project>{579B3FDB-CDAD-44E1-8417-885C38E49A0E}</Project>
- <Name>ServiceStack.Text</Name>
- </ProjectReference>
<ProjectReference Include="..\Northwind.Common\Northwind.Common.csproj">
<Project>{495EBC3A-0F73-4D25-9641-D6ECA70D0026}</Project>
<Name>Northwind.Common</Name>
View
14 src/Northwind.Benchmarks/Northwind.Benchmarks/Serialization/SerializationTestBase.cs
@@ -291,6 +291,13 @@ public T With_DataContractSerializer<T>(T dto)
return Utils.DeserializeDCS<T>(dtoString);
}
+ public T With_NetDataContractSerializer<T>(T dto)
+ {
+ var dtoString = Utils.SerializeNetDCS(dto);
+ LogDto(dtoString);
+ return Utils.DeserializeNetDCS<T>(dtoString);
+ }
+
public T With_DataContractJsonSerializer<T>(T dto)
{
var dtoString = Utils.SerializeDCJS(dto);
@@ -313,6 +320,7 @@ protected void AssertEqual<T>(T dto, T originalDto)
protected void AssertAllAreEqual<T>(T dto)
{
AssertEqual(With_DataContractSerializer(dto), dto);
+ AssertEqual(With_NetDataContractSerializer(dto), dto);
AssertEqual(With_DataContractJsonSerializer(dto), dto);
try
{
@@ -375,6 +383,12 @@ protected void SerializeDto<T>(T dto)
() => Utils.DeserializeDCS<T>(dtoMsXml)
);
+ var dtoMsNetXml = Utils.SerializeNetDCS(dto);
+ RecordRunResults("MS NetDataContractSerializer " + typeof(NetDataContractSerializer).AssemblyVersion(), dtoMsNetXml,
+ () => Utils.SerializeNetDCS(dto),
+ () => Utils.DeserializeNetDCS<T>(dtoMsNetXml)
+ );
+
var dtoMsJson = Utils.SerializeDCJS(dto);
RecordRunResults("MS JsonDataContractSerializer " + typeof(DataContractJsonSerializer).AssemblyVersion(), dtoMsJson,
() => Utils.SerializeDCJS(dto),
View
43 src/Northwind.Benchmarks/Northwind.Benchmarks/Serialization/Utils.cs
@@ -199,6 +199,49 @@ public static string SerializeDCS<T>(T from)
}
}
+ public static T DeserializeNetDCS<T>(string xml)
+ {
+ var type = typeof(T);
+ return (T)DeserializeNetDCS(xml, type);
+ }
+
+ public static object DeserializeNetDCS(string xml, Type type)
+ {
+ try
+ {
+ var bytes = Encoding.UTF8.GetBytes(xml);
+
+ using (var reader = XmlDictionaryReader.CreateTextReader(bytes, new XmlDictionaryReaderQuotas()))
+ {
+ var serializer = new NetDataContractSerializer();
+ return serializer.ReadObject(reader);
+ }
+ }
+ catch (Exception ex)
+ {
+ throw new SerializationException("DeserializeNetDataContract: Error converting type: " + ex.Message, ex);
+ }
+ }
+
+ public static string SerializeNetDCS<T>(T from)
+ {
+ try
+ {
+ using (var stream = new MemoryStream())
+ {
+ var serializer = new NetDataContractSerializer();
+ serializer.Serialize(stream, from);
+ stream.Seek(0, SeekOrigin.Begin);
+ var reader = new StreamReader(stream);
+ return reader.ReadToEnd();
+ }
+ }
+ catch (Exception ex)
+ {
+ throw new SerializationException(string.Format("SerializeNetDataContract: Error serializing object of type {0}", from.GetType().FullName), ex);
+ }
+ }
+
public static object DeserializeDCJS(string json, Type returnType)
{
try
Something went wrong with that request. Please try again.