Optimize calculation of standard deviation.

This commit is contained in:
Bartosz Taudul 2019-03-14 01:23:37 +01:00
parent f57cac9042
commit a0299cc63a
3 changed files with 6 additions and 7 deletions

View File

@ -6029,14 +6029,10 @@ void View::DrawFindZone()
TextFocused( "Median time:", TimeToString( m_findZone.median ) );
if( m_findZone.sorted.size() > 1 )
{
const auto sz = m_findZone.sorted.size();
const auto avg = m_findZone.average;
double ss = 0;
for( auto& v : m_findZone.sorted )
{
const auto d = double( v ) - avg;
ss += d*d;
}
const auto sd = sqrt( ss / ( m_findZone.sorted.size() - 1 ) );
const auto ss = zoneData.sumSq - 2. * zoneData.total * avg + avg * avg * sz;
const auto sd = sqrt( ss / ( sz - 1 ) );
ImGui::SameLine();
ImGui::Spacing();

View File

@ -2590,6 +2590,7 @@ void Worker::ProcessZoneEnd( const QueueZoneEnd& ev )
slz.min = std::min( slz.min, timeSpan );
slz.max = std::max( slz.max, timeSpan );
slz.total += timeSpan;
slz.sumSq += double( timeSpan ) * timeSpan;
if( zone->child >= 0 )
{
for( auto& v : GetZoneChildren( zone->child ) )
@ -3587,6 +3588,7 @@ void Worker::ReadTimelineUpdateStatistics( ZoneEvent* zone, uint16_t thread )
slz.min = std::min( slz.min, timeSpan );
slz.max = std::max( slz.max, timeSpan );
slz.total += timeSpan;
slz.sumSq += double( timeSpan ) * timeSpan;
if( zone->child >= 0 )
{
for( auto& v : GetZoneChildren( zone->child ) )

View File

@ -86,6 +86,7 @@ private:
int64_t min = std::numeric_limits<int64_t>::max();
int64_t max = std::numeric_limits<int64_t>::min();
int64_t total = 0;
double sumSq = 0;
int64_t selfMin = std::numeric_limits<int64_t>::max();
int64_t selfMax = std::numeric_limits<int64_t>::min();
int64_t selfTotal = 0;