This commit is contained in:
neuecc 2017-03-11 22:55:46 +09:00
Родитель 91275336b7
Коммит 27a96994c1
10 изменённых файлов: 538 добавлений и 3 удалений

Просмотреть файл

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
VisualStudioVersion = 15.0.26206.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC}"
EndProject
@ -47,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessagePackAnalyzer.Vsix",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamarinAndroid", "sandbox\XamarinAndroid\XamarinAndroid.csproj", "{307A14EF-C896-4024-BD80-95A55B22C2AB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PertNetFramework", "sandbox\PertNetFramework\PertNetFramework.csproj", "{014A3DCE-50A6-4774-A4C1-C66EEAB67133}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -207,6 +209,18 @@ Global
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Release|x86.ActiveCfg = Release|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Release|x86.Build.0 = Release|Any CPU
{307A14EF-C896-4024-BD80-95A55B22C2AB}.Release|x86.Deploy.0 = Release|Any CPU
{014A3DCE-50A6-4774-A4C1-C66EEAB67133}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{014A3DCE-50A6-4774-A4C1-C66EEAB67133}.Debug|Any CPU.Build.0 = Debug|Any CPU
{014A3DCE-50A6-4774-A4C1-C66EEAB67133}.Debug|x64.ActiveCfg = Debug|Any CPU
{014A3DCE-50A6-4774-A4C1-C66EEAB67133}.Debug|x64.Build.0 = Debug|Any CPU
{014A3DCE-50A6-4774-A4C1-C66EEAB67133}.Debug|x86.ActiveCfg = Debug|Any CPU
{014A3DCE-50A6-4774-A4C1-C66EEAB67133}.Debug|x86.Build.0 = Debug|Any CPU
{014A3DCE-50A6-4774-A4C1-C66EEAB67133}.Release|Any CPU.ActiveCfg = Release|Any CPU
{014A3DCE-50A6-4774-A4C1-C66EEAB67133}.Release|Any CPU.Build.0 = Release|Any CPU
{014A3DCE-50A6-4774-A4C1-C66EEAB67133}.Release|x64.ActiveCfg = Release|Any CPU
{014A3DCE-50A6-4774-A4C1-C66EEAB67133}.Release|x64.Build.0 = Release|Any CPU
{014A3DCE-50A6-4774-A4C1-C66EEAB67133}.Release|x86.ActiveCfg = Release|Any CPU
{014A3DCE-50A6-4774-A4C1-C66EEAB67133}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -224,5 +238,6 @@ Global
{2F9A6E0C-DE95-4460-96B7-EB72BBEAEE9E} = {86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC}
{09B87BEB-D9A3-4EEB-B56A-ED53D27DF1A3} = {86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC}
{307A14EF-C896-4024-BD80-95A55B22C2AB} = {BF4C4202-5015-4FBD-80E6-D0F36A06F700}
{014A3DCE-50A6-4774-A4C1-C66EEAB67133} = {BF4C4202-5015-4FBD-80E6-D0F36A06F700}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

Просмотреть файл

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{014A3DCE-50A6-4774-A4C1-C66EEAB67133}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>PertNetFramework</RootNamespace>
<AssemblyName>PertNetFramework</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MsgPack, Version=0.9.0.0, Culture=neutral, PublicKeyToken=a2625990d5dc0167, processorArchitecture=MSIL">
<HintPath>..\..\packages\MsgPack.Cli.0.9.0-beta2\lib\net46\MsgPack.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.10.0.1-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="protobuf-net, Version=2.1.0.0, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
<HintPath>..\..\packages\protobuf-net.2.1.0\lib\net451\protobuf-net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="ZeroFormatter, Version=1.6.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\ZeroFormatter.1.6.4\lib\net45\ZeroFormatter.dll</HintPath>
</Reference>
<Reference Include="ZeroFormatter.Interfaces, Version=1.6.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\ZeroFormatter.Interfaces.1.6.4\lib\net45\ZeroFormatter.Interfaces.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MessagePack\MessagePack.csproj">
<Project>{7abb33ee-a2f1-492b-8daf-5df89f0f0b79}</Project>
<Name>MessagePack</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,352 @@
using MessagePack;
using System.Linq;
using MessagePack.Formatters;
using MessagePack.Resolvers;
using System;
using System.Diagnostics;
using System.IO;
using ZeroFormatter;
using System.Collections.Generic;
using MessagePack.Internal;
using ProtoBuf;
using System.Collections;
using Newtonsoft.Json;
using System.Text;
using System.IO.Compression;
namespace PerfnetFramework
{
[ZeroFormattable]
[ProtoBuf.ProtoContract]
[MessagePackObject]
public class Person : IEquatable<Person>
{
[Index(0)]
[Key(0)]
[MsgPack.Serialization.MessagePackMember(0)]
[ProtoMember(1)]
public virtual int Age { get; set; }
[Index(1)]
[Key(1)]
[MsgPack.Serialization.MessagePackMember(1)]
[ProtoMember(2)]
public virtual string FirstName { get; set; }
[Index(2)]
[Key(2)]
[MsgPack.Serialization.MessagePackMember(2)]
[ProtoMember(3)]
public virtual string LastName { get; set; }
[Index(3)]
[MsgPack.Serialization.MessagePackMember(3)]
[Key(3)]
[ProtoMember(4)]
public virtual Sex Sex { get; set; }
public bool Equals(Person other)
{
return Age == other.Age && FirstName == other.FirstName && LastName == other.LastName && Sex == other.Sex;
}
}
public enum Sex : sbyte
{
Unknown, Male, Female,
}
class Program
{
static void Main(string[] args)
{
var bytes = new byte[0];
MessagePackBinary.WriteString(ref bytes, 0, "あいうえおあいうえおあいうえお");
var p = new Person
{
Age = 99999,
FirstName = "Windows",
LastName = "Server",
Sex = Sex.Male,
};
Person[] l = Enumerable.Range(1, 100).Select(x => new Person { Age = x, FirstName = "Windows", LastName = "Server", Sex = Sex.Female }).ToArray();
Benchmark(p);
Console.WriteLine();
Benchmark(l);
}
static void Benchmark<T>(T target)
{
const int Iteration = 10000; // 10000
var jsonSerializer = new JsonSerializer();
var msgpack = MsgPack.Serialization.SerializationContext.Default;
msgpack.GetSerializer<T>().PackSingleObject(target);
MessagePack.MessagePackSerializer.Serialize(target);
LZ4MessagePackSerializer.Serialize(target);
ZeroFormatter.ZeroFormatterSerializer.Serialize(target);
ProtoBuf.Serializer.Serialize(new MemoryStream(), target);
jsonSerializer.Serialize(new JsonTextWriter(new StringWriter()), target);
Console.WriteLine(typeof(T).Name + " serialization test");
Console.WriteLine();
Console.WriteLine("Serialize::");
byte[] data = null;
byte[] data0 = null;
byte[] data1 = null;
byte[] data2 = null;
byte[] data3 = null;
byte[] dataJson = null;
byte[] dataGzipJson = null;
using (new Measure("MsgPack-Cli"))
{
for (int i = 0; i < Iteration; i++)
{
data = msgpack.GetSerializer<T>().PackSingleObject(target);
}
}
using (new Measure("MessagePack-CSharp"))
{
for (int i = 0; i < Iteration; i++)
{
data0 = MessagePack.MessagePackSerializer.Serialize(target);
}
}
using (new Measure("MessagePack(LZ4)"))
{
for (int i = 0; i < Iteration; i++)
{
data3 = LZ4MessagePackSerializer.Serialize(target);
}
}
using (new Measure("ZeroFormatter"))
{
for (int i = 0; i < Iteration; i++)
{
data1 = ZeroFormatter.ZeroFormatterSerializer.Serialize(target);
}
}
using (new Measure("JsonNet"))
{
for (int i = 0; i < Iteration; i++)
{
using (var ms = new MemoryStream())
using (var sw = new StreamWriter(ms, Encoding.UTF8, 1024, true))
using (var jw = new JsonTextWriter(sw))
{
jsonSerializer.Serialize(jw, target);
}
}
}
using (new Measure("JsonNet+Gzip"))
{
for (int i = 0; i < Iteration; i++)
{
using (var ms = new MemoryStream())
using (var gzip = new GZipStream(ms, CompressionLevel.Fastest))
using (var sw = new StreamWriter(gzip, Encoding.UTF8, 1024, true))
using (var jw = new JsonTextWriter(sw))
{
jsonSerializer.Serialize(jw, target);
}
}
}
using (new Measure("protobuf-net"))
{
for (int i = 0; i < Iteration; i++)
{
using (var ms = new MemoryStream())
{
ProtoBuf.Serializer.Serialize(ms, target);
}
}
}
using (var ms = new MemoryStream())
{
ProtoBuf.Serializer.Serialize(ms, target);
data2 = ms.ToArray();
}
using (var ms = new MemoryStream())
{
using (var sw = new StreamWriter(ms, Encoding.UTF8, 1024, true))
using (var jw = new JsonTextWriter(sw))
{
jsonSerializer.Serialize(jw, target);
}
dataJson = ms.ToArray();
}
using (var ms = new MemoryStream())
{
using (var gzip = new GZipStream(ms, CompressionLevel.Fastest))
using (var sw = new StreamWriter(gzip, Encoding.UTF8, 1024, true))
using (var jw = new JsonTextWriter(sw))
{
jsonSerializer.Serialize(jw, target);
}
dataGzipJson = ms.ToArray();
}
msgpack.GetSerializer<T>().UnpackSingleObject(data);
MessagePack.MessagePackSerializer.Deserialize<T>(data0);
//ZeroFormatterSerializer.Deserialize<T>(data1);
ProtoBuf.Serializer.Deserialize<T>(new MemoryStream(data2));
LZ4MessagePackSerializer.Deserialize<T>(data3);
jsonSerializer.Deserialize<T>(new JsonTextReader(new StreamReader(new MemoryStream(dataJson))));
Console.WriteLine();
Console.WriteLine("Deserialize::");
using (new Measure("MsgPack-Cli"))
{
for (int i = 0; i < Iteration; i++)
{
msgpack.GetSerializer<T>().UnpackSingleObject(data);
}
}
using (new Measure("MessagePack-CSharp"))
{
for (int i = 0; i < Iteration; i++)
{
MessagePack.MessagePackSerializer.Deserialize<T>(data0);
}
}
using (new Measure("MessagePack(LZ4)"))
{
for (int i = 0; i < Iteration; i++)
{
LZ4MessagePackSerializer.Deserialize<T>(data3);
}
}
using (new Measure("ZeroFormatter"))
{
for (int i = 0; i < Iteration; i++)
{
ZeroFormatterSerializer.Deserialize<T>(data1);
}
}
using (new Measure("JsonNet"))
{
for (int i = 0; i < Iteration; i++)
{
using (var ms = new MemoryStream(dataJson))
using (var sr = new StreamReader(ms, Encoding.UTF8))
using (var jr = new JsonTextReader(sr))
{
jsonSerializer.Deserialize<T>(jr);
}
}
}
using (new Measure("JsonNet+Gzip"))
{
for (int i = 0; i < Iteration; i++)
{
using (var ms = new MemoryStream(dataGzipJson))
using (var gzip = new GZipStream(ms, CompressionMode.Decompress))
using (var sr = new StreamReader(gzip, Encoding.UTF8))
using (var jr = new JsonTextReader(sr))
{
jsonSerializer.Deserialize<T>(jr);
}
}
}
using (new Measure("protobuf-net"))
{
for (int i = 0; i < Iteration; i++)
{
using (var ms = new MemoryStream(data2))
{
ProtoBuf.Serializer.Deserialize<T>(ms);
}
}
}
Console.WriteLine();
Console.WriteLine("FileSize::");
var label = "";
label = "MsgPack-Cli"; Console.WriteLine($"{label,20} {data.Length} Byte");
label = "MessagePack-CSharp"; Console.WriteLine($"{label,20} {data0.Length} Byte");
label = "MessagePack(LZ4)"; Console.WriteLine($"{label,20} {data3.Length} Byte");
label = "ZeroFormatter"; Console.WriteLine($"{label,20} {data1.Length} Byte");
label = "protobuf-net"; Console.WriteLine($"{label,20} {data2.Length} Byte");
label = "JsonNet"; Console.WriteLine($"{label,20} {dataJson.Length} Byte");
label = "JsonNet+GZip"; Console.WriteLine($"{label,20} {dataGzipJson.Length} Byte");
Console.WriteLine();
Console.WriteLine();
}
static string ToHumanReadableSize(long size)
{
return ToHumanReadableSize(new Nullable<long>(size));
}
static string ToHumanReadableSize(long? size)
{
if (size == null) return "NULL";
double bytes = size.Value;
if (bytes <= 1024) return bytes.ToString("f2") + " B";
bytes = bytes / 1024;
if (bytes <= 1024) return bytes.ToString("f2") + " KB";
bytes = bytes / 1024;
if (bytes <= 1024) return bytes.ToString("f2") + " MB";
bytes = bytes / 1024;
if (bytes <= 1024) return bytes.ToString("f2") + " GB";
bytes = bytes / 1024;
if (bytes <= 1024) return bytes.ToString("f2") + " TB";
bytes = bytes / 1024;
if (bytes <= 1024) return bytes.ToString("f2") + " PB";
bytes = bytes / 1024;
if (bytes <= 1024) return bytes.ToString("f2") + " EB";
bytes = bytes / 1024;
return bytes + " ZB";
}
}
struct Measure : IDisposable
{
string label;
Stopwatch sw;
public Measure(string label)
{
this.label = label;
System.GC.Collect(2, GCCollectionMode.Forced, blocking: true);
this.sw = Stopwatch.StartNew();
}
public void Dispose()
{
sw.Stop();
Console.WriteLine($"{ label,20} {sw.Elapsed.TotalMilliseconds} ms");
System.GC.Collect(2, GCCollectionMode.Forced, blocking: true);
}
}
}

Просмотреть файл

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
// アセンブリに関連付けられている情報を変更するには、
// これらの属性値を変更してください。
[assembly: AssemblyTitle("PertNetFramework")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PertNetFramework")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible を false に設定すると、このアセンブリ内の型は COM コンポーネントから
// 参照できなくなります。COM からこのアセンブリ内の型にアクセスする必要がある場合は、
// その型の ComVisible 属性を true に設定してください。
[assembly: ComVisible(false)]
// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります
[assembly: Guid("014a3dce-50a6-4774-a4c1-c66eeab67133")]
// アセンブリのバージョン情報は次の 4 つの値で構成されています:
//
// メジャー バージョン
// マイナー バージョン
// ビルド番号
// Revision
//
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MsgPack.Cli" version="0.9.0-beta2" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.1-beta1" targetFramework="net461" />
<package id="protobuf-net" version="2.1.0" targetFramework="net461" />
<package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net461" />
<package id="System.ValueTuple" version="4.3.0" targetFramework="net461" />
<package id="ZeroFormatter" version="1.6.4" targetFramework="net461" />
<package id="ZeroFormatter.Interfaces" version="1.6.4" targetFramework="net461" />
</packages>

Просмотреть файл

@ -113,6 +113,11 @@ namespace Sandbox
{
static void Main(string[] args)
{
var bytes = new byte[0];
MessagePackBinary.WriteString(ref bytes, 0, "あいうえおあいうえおあいうえお");
var p = new Person
{
Age = 99999,
@ -125,6 +130,7 @@ namespace Sandbox
Benchmark(p);
Console.WriteLine();
Benchmark(l);
}
static void Benchmark<T>(T target)

Просмотреть файл

@ -68,4 +68,8 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
</Project>

Просмотреть файл

@ -192,5 +192,32 @@ namespace MessagePack.Tests
var binary = MessagePackSerializer.Serialize(now);
MessagePackSerializer.Deserialize<DateTimeOffset>(binary).Is(now);
}
[Fact]
public void StringTest_Part2()
{
var a = "あいうえお";
var b = new String('あ', 20);
var c = new String('あ', 130);
var d = new String('あ', 40000);
byte[] bytesA = null;
MessagePackBinary.WriteString(ref bytesA, 0, a).Is(Encoding.UTF8.GetByteCount(a) + 1);
byte[] bytesB = null;
MessagePackBinary.WriteString(ref bytesB, 0, b).Is(Encoding.UTF8.GetByteCount(b) + 2);
byte[] bytesC = null;
MessagePackBinary.WriteString(ref bytesC, 0, c).Is(Encoding.UTF8.GetByteCount(c) + 3);
byte[] bytesD = null;
MessagePackBinary.WriteString(ref bytesD, 0, d).Is(Encoding.UTF8.GetByteCount(d) + 5);
int readSize = 0;
MessagePackBinary.ReadString(bytesA, 0, out readSize).Is(a);
MessagePackBinary.ReadString(bytesB, 0, out readSize).Is(b);
MessagePackBinary.ReadString(bytesC, 0, out readSize).Is(c);
MessagePackBinary.ReadString(bytesD, 0, out readSize).Is(d);
}
}
}

Просмотреть файл

@ -532,8 +532,7 @@ namespace MessagePack.Tests
var referencePacked = packer.PackString(target);
referencePacked.Position.Is(returnLength);
referencePacked.Position.Is(bytes.Length);
stream.ToArray().SequenceEqual(bytes).IsTrue();
stream.ToArray().SequenceEqual(bytes.Take(returnLength).ToArray()).IsTrue();
int readSize;
MessagePackBinary.ReadString(bytes, 0, out readSize).Is(target);