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

Develop #2

Merged
merged 2 commits into from
Feb 12, 2021
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
43 changes: 43 additions & 0 deletions src/Binaron.Serializer.Debug.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29411.108
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Binaron.Serializer", "Binaron.Serializer\Binaron.Serializer.csproj", "{7A418C08-D0C0-4080-88C5-8A104C8D3FC1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Binaron.Serializer.Benchmark", "Binaron.Serializer.Benchmark\Binaron.Serializer.Benchmark.csproj", "{20A3FAA1-27F4-4001-8302-7FE5352AB066}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Binaron.Serializer.Tests", "Binaron.Serializer.Tests\Binaron.Serializer.Tests.csproj", "{47AACE5E-DC48-42AB-8CBD-ADB1FA771E2B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Binaron.Serializer.Debug", "Binaron.Serializer.Debug\Binaron.Serializer.Debug.csproj", "{387628B3-F233-43AD-B06A-7896C56C1B07}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7A418C08-D0C0-4080-88C5-8A104C8D3FC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A418C08-D0C0-4080-88C5-8A104C8D3FC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A418C08-D0C0-4080-88C5-8A104C8D3FC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A418C08-D0C0-4080-88C5-8A104C8D3FC1}.Release|Any CPU.Build.0 = Release|Any CPU
{20A3FAA1-27F4-4001-8302-7FE5352AB066}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20A3FAA1-27F4-4001-8302-7FE5352AB066}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20A3FAA1-27F4-4001-8302-7FE5352AB066}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20A3FAA1-27F4-4001-8302-7FE5352AB066}.Release|Any CPU.Build.0 = Release|Any CPU
{47AACE5E-DC48-42AB-8CBD-ADB1FA771E2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{47AACE5E-DC48-42AB-8CBD-ADB1FA771E2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{47AACE5E-DC48-42AB-8CBD-ADB1FA771E2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{47AACE5E-DC48-42AB-8CBD-ADB1FA771E2B}.Release|Any CPU.Build.0 = Release|Any CPU
{387628B3-F233-43AD-B06A-7896C56C1B07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{387628B3-F233-43AD-B06A-7896C56C1B07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{387628B3-F233-43AD-B06A-7896C56C1B07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{387628B3-F233-43AD-B06A-7896C56C1B07}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BD282BEE-F832-48AE-ABA4-40DB1F133E3F}
EndGlobalSection
EndGlobal
18 changes: 18 additions & 0 deletions src/Binaron.Serializer.Debug/Binaron.Serializer.Debug.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp5.0</TargetFramework>
<RootNamespace>BinSerializerTest</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Binaron.Serializer\Binaron.Serializer.csproj" />
</ItemGroup>

</Project>
260 changes: 260 additions & 0 deletions src/Binaron.Serializer.Debug/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
using Binaron.Serializer;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BinSerializerTest
{
class Program
{
class TestObject
{
public int A { get; set; }
public TestObject()
{

}

public TestObject(int a)
{
A = a;
}
}

class TestObject1
{
public int? A { get; set; }

public TestObject1()
{

}

public TestObject1(int? a)
{
A = a;
}
}

enum E1
{
E11,
E12,
E13
};

class Collector<T> : IEnumerable<T>
{
private List<T> mData = new List<T>();

public T this[int index] => mData[index];
public int Count => mData.Count;

public void Add(T element) => mData.Add(element);

public IEnumerator<T> GetEnumerator() => mData.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => mData.GetEnumerator();
}

public static void Main(string[] args)
{
if (false)
Benchmark();

if (false)
{
Collector<TestObject> c = new Collector<TestObject>() { new TestObject(1), new TestObject(2) };
using (var ms1 = new MemoryStream())
{
BinaronConvert.Serialize(c, ms1);
using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var cr = BinaronConvert.Deserialize<Collector<TestObject>>(ms2);
;
}
}
}

if (true)
{
Collector<TestObject1> c = new Collector<TestObject1>() { new TestObject1(1), null, new TestObject1(null), new TestObject1(2) };
using (var ms1 = new MemoryStream())
{
BinaronConvert.Serialize(c, ms1);
using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var cr = BinaronConvert.Deserialize<Collector<TestObject1>>(ms2);
;
}
}
}

if (false)
{
Collector<E1> c1 = new Collector<E1>() { E1.E11, E1.E12, E1.E13 };
using (var ms1 = new MemoryStream())
{
BinaronConvert.Serialize(c1, ms1);
using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var cr1 = BinaronConvert.Deserialize<Collector<E1>>(ms2);
;
}
}
}

if (false)
{
List<TestObject> l = new List<TestObject>() { new TestObject(1), null, new TestObject(2) };
using (var ms1 = new MemoryStream())
{
BinaronConvert.Serialize(l, ms1);
using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var l1 = BinaronConvert.Deserialize<List<TestObject>>(ms2);
;
}
}
}

if (false)
{
List<int?> c2 = new List<int?>() { 1, null, 2 };
using (var ms1 = new MemoryStream())
{
BinaronConvert.Serialize(c2, ms1);
using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var cr2 = BinaronConvert.Deserialize<List<int?>>(ms2);
;
}
}
}

if (true)
{
Collector<int?> c2 = new Collector<int?>() { 1, null, 2 };
using (var ms1 = new MemoryStream())
{
BinaronConvert.Serialize(c2, ms1);
using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var cr2 = BinaronConvert.Deserialize<Collector<int?>>(ms2);
;
}

using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var cr2 = BinaronConvert.Deserialize(ms2);
;
}
}
}

if (false)
{
using (var ms1 = new MemoryStream())
{
BinaronConvert.Serialize<int?>(1, ms1);
using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var cr2 = BinaronConvert.Deserialize<int?>(ms2);
;
}
}

using (var ms1 = new MemoryStream())
{
BinaronConvert.Serialize<int?>(null, ms1);
using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var cr2 = BinaronConvert.Deserialize<int?>(ms2);
;
}
}
}




}

private static void Benchmark()
{
Stopwatch sw = new Stopwatch();

{
sw.Reset();
Collector<int> c = new Collector<int>();
for (int i = 0; i < 1000; i++)
c.Add(i);
sw.Start();
for (int i = 0; i < 1000; i++)
{
using (var ms1 = new MemoryStream())
{
BinaronConvert.Serialize(c, ms1);
using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var c2 = BinaronConvert.Deserialize<Collector<int>>(ms2);
}
}
}
sw.Stop();
Console.WriteLine("IEnumerable/invoke {0}", sw.ElapsedMilliseconds);
}

{
sw.Reset();
Collector<short> c = new Collector<short>();
for (int i = 0; i < 1000; i++)
c.Add((short)i);
sw.Start();
for (int i = 0; i < 1000; i++)
{
using (var ms1 = new MemoryStream())
{
BinaronConvert.Serialize(c, ms1);
using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var c2 = BinaronConvert.Deserialize<Collector<short>>(ms2);
}
}
}
sw.Stop();
Console.WriteLine("IEnumerable/reflection {0}", sw.ElapsedMilliseconds);
}

{
sw.Reset();
List<int> c = new List<int>();
for (int i = 0; i < 1000; i++)
c.Add(i);
sw.Start();
for (int i = 0; i < 1000; i++)
{
using (var ms1 = new MemoryStream())
{
BinaronConvert.Serialize(c, ms1);
using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var c2 = BinaronConvert.Deserialize<List<int>>(ms2);
}
}
}
sw.Stop();
Console.WriteLine("List {0}", sw.ElapsedMilliseconds);
}




}
}
}
39 changes: 39 additions & 0 deletions src/Binaron.Serializer.Tests/CustomTestCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Binaron.Serializer.Tests
{
public class CustomTestCollection<T> : IEnumerable<T>
{
private List<T> List = new List<T>();

public T this[int index] => List[index];

public int Count => List.Count;

public void Add(T value) => List.Add(value);


public IEnumerator<T> GetEnumerator() => List.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => List.GetEnumerator();

public class TestCollectionObject
{
public T A { get; set; }

public TestCollectionObject()
{
}

public TestCollectionObject(T a)
{
A = a;
}
}
}
}
Loading