I use C# .net 4.0 and don’t see any possible way to do it, but maybe you know? 🙂
I do my serialization in that way:
public static void SaveCollection<T>(string file_name, T list)
{
BinaryFormatter bf = new BinaryFormatter();
FileStream fs = null;
try
{
fs = new FileStream(Application.StartupPath + "/" + file_name, FileMode.Create);
bf.Serialize(fs, list);
fs.Flush();
fs.Close();
}
catch (Exception exc)
{
if (fs != null)
fs.Close();
string msg = "Unable to save collection {0}\nThe error is {1}";
MessageBox.Show(Form1.ActiveForm, string.Format(msg, file_name, exc.Message));
}
}
So, let’s say you use actually know in advance the size of your object graph, which itself may be difficult, but let’s just assume you do :). You could do this:
Then you could use it like:
This will give you the bytes as they are written, so you could calculate the time using that. Note: it’s possible you might need to override a few more methods of the stream class.