Improve time comparing display.

This commit is contained in:
Martijn Courteaux 2024-05-21 19:08:16 +02:00
parent f704c57f98
commit 717e545158

View File

@ -185,42 +185,35 @@ static void PrintDiff( const std::string& diff )
} }
} }
static void PrintSpeedupOrSlowdown( double time_this, double time_external ) static void PrintSpeedupOrSlowdown( double time_this, double time_external, const char *metric )
{ {
const char *label, *label2; const char *label, *label2;
const char *time_diff = TimeToString( abs( time_external - time_this ) ); const char *time_diff = TimeToString( abs( time_external - time_this ) );
ImVec4 color; ImVec4 color;
double factor; double factor = time_this / time_external;
if( time_external >= time_this ) if( time_external >= time_this )
{ {
label = "Speedup:", label2 = "faster"; label = "less than external", label2 = "faster";
color = ImVec4( 0.1f, 0.6f, 0.1f, 1.0f); color = ImVec4( 0.1f, 0.6f, 0.1f, 1.0f );
factor = time_external / time_this;
} else { } else {
label = "Slowdown:", label2 = "slower"; label = "more than external", label2 = "slower";
color = ImVec4( 0.8f, 0.1f, 0.1f, 1.0f ); color = ImVec4( 0.8f, 0.1f, 0.1f, 1.0f );
factor = time_this / time_external;
} }
TextColoredUnformatted( color, label ); TextColoredUnformatted( color, metric );
ImGui::SameLine(); ImGui::SameLine();
TextColoredUnformatted(color, time_diff ); TextColoredUnformatted(color, time_diff );
ImGui::SameLine(); ImGui::SameLine();
TextColoredUnformatted( color, label2 ); TextColoredUnformatted( color, label );
ImGui::SameLine(); ImGui::SameLine();
ImGui::Spacing(); ImGui::Spacing();
ImGui::SameLine(); ImGui::SameLine();
char buf[64]; char buf[64];
memcpy( buf, "( ", 2 ); memcpy( buf, "(Time factor compared to external: ", 35 );
char *ptr = &buf[2]; char *ptr = &buf[35];
ptr = PrintFloat( ptr, buf + sizeof(buf), factor, 3 ); ptr = PrintFloat( ptr, buf + sizeof(buf), factor, 3 );
memcpy( ptr, "x ", 2 ); memcpy( ptr, ")", 2 );
ptr += 2; ptr += 23;
int ssz = strlen( label2 );
memcpy( ptr, label2, ssz );
ptr += ssz;
memcpy( ptr, " )", 3 );
TextDisabledUnformatted( buf ); TextDisabledUnformatted( buf );
} }
void View::DrawCompare() void View::DrawCompare()
@ -1004,7 +997,7 @@ void View::DrawCompare()
ImGui::SameLine(); ImGui::SameLine();
TextFocused( "Total time (ext.):", TimeToString( total1 * adj1 ) ); TextFocused( "Total time (ext.):", TimeToString( total1 * adj1 ) );
ImGui::Indent(); ImGui::Indent();
PrintSpeedupOrSlowdown( total0 * adj0, total1 * adj1 ); PrintSpeedupOrSlowdown( total0 * adj0, total1 * adj1, "Total time" );
ImGui::Unindent(); ImGui::Unindent();
TextFocused( "Max counts:", cumulateTime ? TimeToString( maxVal ) : RealToString( floor( maxVal ) ) ); TextFocused( "Max counts:", cumulateTime ? TimeToString( maxVal ) : RealToString( floor( maxVal ) ) );
@ -1059,7 +1052,8 @@ void View::DrawCompare()
TooltipIfHovered( "Standard deviation" ); TooltipIfHovered( "Standard deviation" );
} }
ImGui::Indent(); ImGui::Indent();
PrintSpeedupOrSlowdown( m_compare.average[0], m_compare.average[1] ); PrintSpeedupOrSlowdown( m_compare.average[0], m_compare.average[1], "Mean time" );
PrintSpeedupOrSlowdown( m_compare.median[0], m_compare.median[1], "Median time" );
ImGui::Unindent(); ImGui::Unindent();
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0xDD/511.f, 0xDD/511.f, 0x22/511.f, 1.f ) ); ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0xDD/511.f, 0xDD/511.f, 0x22/511.f, 1.f ) );