Permalink
Browse files

added NBench performance tests

  • Loading branch information...
1 parent 3163dd3 commit 689fb6ddf7e4b916f311aedabc11920b5b632b76 @Horusiath Horusiath committed Nov 24, 2016
View
@@ -22,6 +22,8 @@ bld/
[Bb]in/
[Oo]bj/
.fake/
+TestResults/
+PerfResults/
# Visual Studo 2015 cache/options directory
.vs/
@@ -0,0 +1,6 @@
+namespace Wire.Tests.Performance
+{
+ public static class BenchmarkHelper
+ {
+ }
+}
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Wire.Tests.Performance")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Wire.Tests.Performance")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("44afcd2c-2220-4b52-817a-bd9c8b600e05")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,104 @@
+using System.Collections.Generic;
+using System.IO;
+using NBench;
+
+namespace Wire.Tests.Performance
+{
+ public class SerializeCollectionsBenchmark
+ {
+ #region init
+
+ public const int Iterations = 5;
+
+ private Serializer _serializer;
+ private MemoryStream _stream;
+
+ [PerfSetup]
+ public void Setup()
+ {
+ _serializer = new Serializer();
+ _stream = new MemoryStream();
+ }
+
+ [PerfCleanup]
+ public void Cleanup()
+ {
+ _stream.Dispose();
+ _stream = null;
+ _serializer = null;
+ }
+
+ #endregion
+
+ [PerfBenchmark(Description = "Benchmark byte array serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_ByteArray()
+ {
+ _serializer.Serialize(new byte[] { 123, 134, 11 }, _stream);
+ }
+
+ [PerfBenchmark(Description = "Benchmark string array serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_StringArray()
+ {
+ _serializer.Serialize(new string[] { "abc", "cbd0", "sdsd4", "4dfg" }, _stream);
+ }
+
+ [PerfBenchmark(Description = "Benchmark dictionary serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_Dictionary()
+ {
+ var dictionary = new Dictionary<string, string>
+ {
+ ["abc"] = "aaa",
+ ["dsdf"] = "asdab"
+ };
+ _serializer.Serialize(dictionary, _stream);
+ }
+
+ [PerfBenchmark(Description = "Benchmark list serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_List()
+ {
+ _serializer.Serialize(new List<string> { "asdad", "asdabs3", "dfsdf9", "asdf4r", "sfsdf44g" }, _stream);
+ }
+
+ [PerfBenchmark(Description = "Benchmark linked list serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_LinkedList()
+ {
+ var list = new LinkedList<string>(new [] { "asdad", "asdabs3", "dfsdf9", "asdf4r", "sfsdf44g" });
+ _serializer.Serialize(list, _stream);
+ }
+
+ [PerfBenchmark(Description = "Benchmark hash set serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_HashSet()
+ {
+ var set = new HashSet<string> { "asdad", "asdabs3", "dfsdf9", "asdf4r", "sfsdf44g" };
+ _serializer.Serialize(set, _stream);
+ }
+
+ [PerfBenchmark(Description = "Benchmark sorted set serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_SortedSet()
+ {
+ var set = new SortedSet<string> { "asdad", "asdabs3", "dfsdf9", "asdf4r", "sfsdf44g" };
+ _serializer.Serialize(set, _stream);
+ }
+ }
+}
@@ -0,0 +1,58 @@
+using System.IO;
+using NBench;
+using Wire.Tests.Performance.Types;
+
+namespace Wire.Tests.Performance
+{
+ public class SerializeComplexObjectsBenchmark
+ {
+ #region init
+
+ public const int Iterations = 5;
+
+ private Serializer _serializer;
+ private MemoryStream _stream;
+
+ private LargeStruct _testStruct;
+ private TypicalPersonData _testPerson;
+
+ [PerfSetup]
+ public void Setup()
+ {
+ _serializer = new Serializer();
+ _stream = new MemoryStream();
+ _testStruct = LargeStruct.Create();
+ _testPerson = TypicalPersonData.MakeRandom();
+ }
+
+ [PerfCleanup]
+ public void Cleanup()
+ {
+ _stream.Dispose();
+ _stream = null;
+ _serializer = null;
+ _testStruct = default(LargeStruct);
+ _testPerson = null;
+ }
+
+ #endregion
+
+ [PerfBenchmark(Description = "Benchmark struct serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_LargeStruct()
+ {
+ _serializer.Serialize(_testStruct, _stream);
+ }
+
+ [PerfBenchmark(Description = "Benchmark large object serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_LargeObject()
+ {
+ _serializer.Serialize(_testPerson, _stream);
+ }
+ }
+}
@@ -0,0 +1,90 @@
+using System.Collections.Generic;
+using System.Collections.Immutable;
+using System.IO;
+using NBench;
+
+namespace Wire.Tests.Performance
+{
+ public class SerializeImmutableCollectionsBenchmark
+ {
+ #region init
+
+ public const int Iterations = 5;
+
+ private Serializer _serializer;
+ private MemoryStream _stream;
+
+ [PerfSetup]
+ public void Setup()
+ {
+ _serializer = new Serializer();
+ _stream = new MemoryStream();
+ }
+
+ [PerfCleanup]
+ public void Cleanup()
+ {
+ _stream.Dispose();
+ _stream = null;
+ _serializer = null;
+ }
+
+ #endregion
+
+ [PerfBenchmark(Description = "Benchmark immutable array serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_ImmutableArray()
+ {
+ var collection = ImmutableArray.CreateRange(new[] {"abc", "cbd0", "sdsd4", "4dfg"});
+ _serializer.Serialize(collection, _stream);
+ }
+
+ [PerfBenchmark(Description = "Benchmark immutable list serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_ImmutableList()
+ {
+ var collection = ImmutableList.CreateRange(new[] { "abc", "cbd0", "sdsd4", "4dfg" });
+ _serializer.Serialize(collection, _stream);
+ }
+
+ [PerfBenchmark(Description = "Benchmark immutable hash set serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_ImmutableHashSet()
+ {
+ var collection = ImmutableHashSet.CreateRange(new[] { "abc", "cbd0", "sdsd4", "4dfg" });
+ _serializer.Serialize(collection, _stream);
+ }
+
+ [PerfBenchmark(Description = "Benchmark immutable sorted set serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_ImmutableSortedSet()
+ {
+ var collection = ImmutableHashSet.CreateRange(new[] { "abc", "cbd0", "sdsd4", "4dfg" });
+ _serializer.Serialize(collection, _stream);
+ }
+
+ [PerfBenchmark(Description = "Benchmark immutable dictionary serialization",
+ RunMode = RunMode.Iterations, TestMode = TestMode.Test, NumberOfIterations = Iterations)]
+ [TimingMeasurement]
+ [ElapsedTimeAssertion(MaxTimeMilliseconds = 300)]
+ public void Serialize_ImmutableDictionary()
+ {
+ var collection = ImmutableDictionary.CreateRange(new[]
+ {
+ new KeyValuePair<string, string>("key1", "value1"),
+ new KeyValuePair<string, string>("key2", "value2"),
+ new KeyValuePair<string, string>("key3", "value3"),
+ new KeyValuePair<string, string>("key4", "value4"),
+ });
+ _serializer.Serialize(collection, _stream);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 689fb6d

Please sign in to comment.