Skip to content

Instantly share code, notes, and snippets.

@kazuk kazuk/Program.cs
Created Dec 22, 2012

Embed
What would you like to do?
performace test for msgpack-cli TestStringMedium
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using MsgPack;
namespace PerfTest
{
class Program
{
static void Main(string[] args)
{
var sw = Stopwatch.StartNew();
for (int i = 0; i < 10; i++)
{
var avg = TestMedium();
}
sw.Stop();
}
private static double TestMedium()
{
Random random = new Random();
var sb = new StringBuilder(1000*1000*200);
var avg = 0.0;
// medium size string
for (int i = 0; i < 100; i++)
{
sb.Length = 0;
int len = (int) random.Next()%100 + (1 << 15);
for (int j = 0; j < len; j++)
{
sb.Append('a' + ((int) random.Next()) & 26);
}
avg = (avg + sb.Length)/2.0;
for (int x = 0; x < 10000; x++)
{
TestString(sb.ToString());
}
}
return avg;
}
private static void TestString(String val)
{
var output = new MemoryStream();
Packer.Create(output).PackString(val);
MessagePackObject obj = UnpackOne(output);
// Assert.AreEqual(val, obj.AsString());
// Assert.IsTrue(obj.IsTypeOf<string>().GetValueOrDefault());
}
private static bool _traceUnpackingBytes = false;
private static MessagePackObject UnpackOne(MemoryStream output)
{
output.Seek(0L, SeekOrigin.Begin);
if (_traceUnpackingBytes)
{
Console.WriteLine("Unpaking:");
foreach (var b in output.ToArray().Take(100))
{
Console.Write(b.ToString("x2"));
}
Console.WriteLine();
}
return Unpacking.UnpackObject(output);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.