我有大约5亿个ExpandoObjects,我想保存到磁盘并再次加载。值是简单类型:
这是我目前保存到磁盘的代码:
BinaryWriter bw = new BinaryWriter(new FileStream(filename, FileMode.Create), Encoding.UTF8);
foreach(ExpandoObject expandoObject in expandoObjects)
{
bw.Write(JsonConvert.SerializeObject(expandoObject));
}
bw.Close();
这是我从磁盘加载的代码:
BinaryReader br = new BinaryReader(new FileStream(filename, FileMode.Open));
while (br.BaseStream.Position < br.BaseStream.Length)
{
ExpandoObject expandoObject = JsonConvert.DeserializeObject<ExpandoObject>(br.ReadString());
expandoObjects.Add(expandoObject);
}
保存到磁盘不是时间关键的,但如果可能的话,加载应该更快。我想知道二进制格式是否会加速这一点。
您对二元方法有什么建议?你认为会有显着的加速吗?