Radically improve frame set histogram performance.

This change exploits the fact that frame set data is sorted, and the
histogram bins can be calculated as distances in the frame-time vectors.
This commit is contained in:
Bartosz Taudul 2018-09-01 14:50:38 +02:00
parent 1bef4b45b7
commit e81218ddaf

View File

@ -6457,26 +6457,32 @@ void View::DrawInfo()
if( m_frameSortData.logTime ) if( m_frameSortData.logTime )
{ {
const auto tMinLog = log10fast( tmin ); const auto tMinLog = log10( tmin );
const auto idt = numBins / ( log10fast( tmax ) - tMinLog ); const auto zmax = ( log10( tmax ) - tMinLog ) / numBins;
auto fit = frames.begin(); auto fit = frames.begin();
while( fit != frames.end() && *fit == 0 ) fit++; while( fit != frames.end() && *fit == 0 ) fit++;
while( fit != frames.end() ) for( int64_t i=0; i<numBins; i++ )
{ {
const auto bin = std::min( numBins - 1, int64_t( ( log10fast( *fit++ ) - tMinLog ) * idt ) ); const auto nextBinVal = int64_t( pow( 10.0, tMinLog + ( i+1 ) * zmax ) );
bins[bin]++; auto nit = std::lower_bound( fit, frames.end(), nextBinVal );
bins[i] = std::distance( fit, nit );
fit = nit;
} }
bins[numBins-1] += std::distance( fit, frames.end() );
} }
else else
{ {
const auto idt = numBins / dt; const auto zmax = tmax - tmin;
auto fit = frames.begin(); auto fit = frames.begin();
while( fit != frames.end() && *fit == 0 ) fit++; while( fit != frames.end() && *fit == 0 ) fit++;
while( fit != frames.end() ) for( int64_t i=0; i<numBins; i++ )
{ {
const auto bin = std::min( numBins - 1, int64_t( ( *fit++ - tmin ) * idt ) ); const auto nextBinVal = ( i+1 ) * zmax / numBins;
bins[bin]++; auto nit = std::lower_bound( fit, frames.end(), nextBinVal );
bins[i] = std::distance( fit, nit );
fit = nit;
} }
bins[numBins-1] += std::distance( fit, frames.end() );
} }
int64_t maxVal = bins[0]; int64_t maxVal = bins[0];