|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using consoletest.DataObjects;
namespace consoletest
{
public static partial class Benchmarks
{
private static void BinaryFormatter_Deserialize()
{
Console.WriteLine();
Console.Write("bin deserialize");
FastJsonBenchmarkClass c = CreateTestedObject();
List<long> testRuns = new List<long>();
for (int pp = 0; pp < tcount; pp++)
{
stopwatch.Reset();
stopwatch.Start();
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, c);
FastJsonBenchmarkClass deserializedStore = null;
//Console.WriteLine(" size = " +ms.Length);
for (int i = 0; i < count; i++)
{
ms.Seek(0L, SeekOrigin.Begin);
deserializedStore = (FastJsonBenchmarkClass)bf.Deserialize(ms);
}
stopwatch.Stop();
Console.Write("\t" + stopwatch.ElapsedMilliseconds);
testRuns.Add(stopwatch.ElapsedMilliseconds);
}
WriteAverage(true);
}
private static void BinaryFormatter_Serialize()
{
Console.Write("\r\nbin serialize");
FastJsonBenchmarkClass c = CreateTestedObject();
InitTestRun();
for (int pp = 0; pp < tcount; pp++)
{
stopwatch.Reset();
stopwatch.Start();
DateTime st = DateTime.Now;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
for (int i = 0; i < count; i++)
{
ms = new MemoryStream();
bf.Serialize(ms, c);
}
stopwatch.Stop();
Console.Write("\t" + stopwatch.ElapsedMilliseconds);
testRunDurations.Add(stopwatch.ElapsedMilliseconds);
}
WriteAverage(true);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.