Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update performance tests #460

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
155 changes: 0 additions & 155 deletions test/ExtendedXmlSerializer.Tests.Performance/Benchmarks.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// MIT License
//
// Copyright (c) 2016-2018 Wojciech Nagórski
// Michael DeMond
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.IO;
using System.Text;
using System.Xml;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using ExtendedXmlSerializer.Configuration;
using ExtendedXmlSerializer.ExtensionModel.Xml;
using ExtendedXmlSerializer.Tests.Performance.Model;

namespace ExtendedXmlSerializer.Tests.Performance
{
[ShortRunJob]
public class ExtendedXmlSerializerTest
{
readonly IExtendedXmlSerializer _serializer = new ConfigurationContainer().EnableClassicMode().Create();

readonly TestClassOtherClass _obj = new TestClassOtherClass().Init();
readonly byte[] _data;

readonly IXmlReaderFactory _readerFactory = new XmlReaderFactory();

public ExtendedXmlSerializerTest()
{
_data = Encoding.UTF8.GetBytes(SerializationClassWithPrimitive());
DeserializationClassWithPrimitive();
}

[Benchmark]
public string SerializationClassWithPrimitive()
{
using (var stream = new MemoryStream())
{
using (var writer = XmlWriter.Create(stream))
{
_serializer.Serialize(writer, _obj);
writer.Flush();
stream.Seek(0, SeekOrigin.Begin);
var result = new StreamReader(stream).ReadToEnd();
return result;
}
}
}

[Benchmark]
public object DeserializationClassWithPrimitive()
{
using (var stream = new MemoryStream(_data))
{
using (var reader = _readerFactory.Get(stream))
{
return _serializer.Deserialize(reader);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// MIT License
//
// Copyright (c) 2016-2018 Wojciech Nagórski
// Michael DeMond
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using BenchmarkDotNet.Attributes;
using ExtendedXmlSerializer.Tests.Performance.Model;

namespace ExtendedXmlSerializer.Tests.Performance
{
[ShortRunJob]
public class LegacyExtendedXmlSerializerTest
{
readonly TestClassOtherClass _obj = new TestClassOtherClass();
readonly string _xml;
#pragma warning disable 618
readonly ExtendedXmlSerialization.IExtendedXmlSerializer _serializer =
new ExtendedXmlSerialization.ExtendedXmlSerializer();
#pragma warning restore 618

public LegacyExtendedXmlSerializerTest()
{
_obj.Init();
_xml = SerializationClassWithPrimitive();
DeserializationClassWithPrimitive();
}

[Benchmark]
public string SerializationClassWithPrimitive() => _serializer.Serialize(_obj);

[Benchmark]
public TestClassOtherClass DeserializationClassWithPrimitive() => _serializer.Deserialize<TestClassOtherClass>(_xml);
}
}
77 changes: 77 additions & 0 deletions test/ExtendedXmlSerializer.Tests.Performance/XmlSerializerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// MIT License
//
// Copyright (c) 2016-2018 Wojciech Nagórski
// Michael DeMond
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using BenchmarkDotNet.Attributes;
using ExtendedXmlSerializer.ExtensionModel.Xml;
using ExtendedXmlSerializer.Tests.Performance.Model;

namespace ExtendedXmlSerializer.Tests.Performance
{
[ShortRunJob]
public class XmlSerializerTest
{
readonly IXmlReaderFactory _readerFactory = new XmlReaderFactory();
readonly XmlSerializer _serializer = new XmlSerializer(typeof(TestClassOtherClass));
readonly TestClassOtherClass _obj = new TestClassOtherClass().Init();
readonly byte[] _xml;

public XmlSerializerTest()
{
_xml = Encoding.UTF8.GetBytes(SerializationClassWithPrimitive());
DeserializationClassWithPrimitive();
}

[Benchmark]
public string SerializationClassWithPrimitive()
{
using (var stream = new MemoryStream())
{
using (var writer = XmlWriter.Create(stream))
{
_serializer.Serialize(writer, _obj);
writer.Flush();
stream.Seek(0, SeekOrigin.Begin);
var result = new StreamReader(stream).ReadToEnd();
return result;
}
}
}

[Benchmark]
public object DeserializationClassWithPrimitive()
{
using (var stream = new MemoryStream(_xml))
{
using (var reader = _readerFactory.Get(stream))
{
var result = _serializer.Deserialize(reader);
return result;
}
}
}
}
}