Skip to content

Instantly share code, notes, and snippets.

@stdray
Created September 7, 2017 15:16
Show Gist options
  • Save stdray/02eae70a688df1917bb83f9637937e98 to your computer and use it in GitHub Desktop.
Save stdray/02eae70a688df1917bb83f9637937e98 to your computer and use it in GitHub Desktop.
public class SerializerInfo
{
const double EPSILON = 0.0001;
readonly object _lock = new object();
double _averageSize = 0;
long _count = 0;
public SerializerInfo(XmlSerializer serializer)
{
Serializer = serializer;
}
public SerializerInfo AddIntanceSize(int size)
{
lock (_lock)
{
var delta = (size - _averageSize) / _count;
if (Math.Abs(delta) < EPSILON)
return this;
_count++;
_averageSize += delta;
return this;
}
}
public long AverageSize => (int)Math.Ceiling(_averageSize);
public XmlSerializer Serializer { get; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment