Binary Serialization of DataSets by Dino E

Published Fri, Sep 17 2004 12:45 | William

Even if I tried really hard, I don't think I'd ever be able to make myself not like something Dino Esposito has written.  I know I know, he wouldn't be at Wintellect if he wasn't a total bad a33 but still, he's the man at a lot of different stuff and it's impressive.  Well, ADO.NET 2.0 is something very near and dear to me and he did another great job here.

Filed under:

Comments

# William said on November 9, 2004 2:14 AM:

Binary Serialization of DataSets in .Net Framework 2.0
I read Dino Esposito's article about Binary Serialization of DataSets In ADO.NET 2.0.

DataSet serialization is a real pain in the .Net Framework 1.1.

I made a test to check the size and time it take to serialize a DataSet.
The test included memory serialization of the a DataSet with one table and 20,000 rows.

I tested the serialization with inserted rows.

The tests used BinaryFormatter and was run on framework version 2.0.40607.85.

Here are the results:

.Net framework 1.1
5,220,304 bytes , about 14.3 seconds

.Net framework 2.0 with RemotingFormatter = SerializationFormat.Xml :
5,800,442 bytes , about 13 seconds

.Net framework 2.0 with RemotingFormatter = SerializationFormat.Binary :
1,727,292 bytes , about 1 minutes and 18 seconds


------

It seems that SerializationFormat indeed saves network traffic, but the problem is that it take too much time to create the serialization stream. There was no real performance change with unchanged rows (after calling to AcceptChanges).

Do I miss anything?

Here is the test code:

using System;

using System.Data;

using System.IO;

using System.Runtime.Serialization;

using System.Runtime.Serialization.Formatters.Binary;

class Class1

{

[STAThread]

static void Main(string[] args)

{


//Create a dataset with a scheme

DataSet ds = new DataSet();

DataTable tbl = ds.Tables.Add ("tbl");

tbl.Columns.Add ("a", typeof(int));

tbl.Columns.Add ("b", typeof(int));

tbl.Columns.Add ("c", typeof(string));

tbl.Columns.Add ("d", typeof(int));

tbl.Columns.Add ("e", typeof(int));

tbl.Columns.Add ("f", typeof(string));

tbl.Columns.Add ("g", typeof(Byte));

tbl.Columns.Add ("y", typeof(int));

tbl.Columns.Add ("i", typeof(int));

tbl.Columns.Add ("j", typeof(string));

tbl.Columns.Add ("k", typeof(int));

tbl.Columns.Add ("l", typeof(int));

tbl.Columns.Add ("m", typeof(string));

tbl.Columns.Add ("n", typeof(int));

tbl.Columns.Add ("o", typeof(string));

tbl.Columns.Add ("p", typeof(DateTime));

tbl.Columns.Add ("q", typeof(DateTime));

ds.RemotingFormat = SerializationFormat.Xml;

//Load rows into dataset

for (int i = 0; i < 20000; i++)

{

ds.Tables["tbl"].Rows.Add (new object[] {

0,1,"a",2,3,"ab",4,5,6,7,8,9,10,11,"abcd",DateTime.Now,DateTime.Now});

}

MemoryStream ms;

BinaryFormatter bf = new BinaryFormatter();

//Record the start time

DateTime s = DateTime.Now;

for (int i = 0; i < 10; i++)

{

//Serialize the dataset into memory

using (ms = new MemoryStream())

{

bf.Serialize (ms, ds);

Console.WriteLine (ms.Position);

}

}


//Record the end time

DateTime e = DateTime.Now;

Console.WriteLine (e-s);

Console.WriteLine (System.Environment.Version.ToString());

}

}

Search

This Blog

Tags

Community

Archives

News

My other sites

Cool Stuff

Book Stuff

Security

ORM

Data Access

Funny Stuff

Compact Framework Stuff

Web Casts

My KnowledgeBase Articles

My MVP Profile

Design Patterns

Performance

Debugging

Remoting

My Fellow Authors

My Books

LINQ

Misc

Speech

Syndication

Email Notifications