Created
September 7, 2017 15:16
-
-
Save stdray/02eae70a688df1917bb83f9637937e98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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