Skip to content

Commit

Permalink
refactor sc_sim.cpp
Browse files Browse the repository at this point in the history
- remove some unused functions
- more range-based for loops
- refactor progress() functions.
  • Loading branch information
scamille committed Sep 12, 2015
1 parent 70ec527 commit 0159e92
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 232 deletions.
3 changes: 1 addition & 2 deletions engine/sc_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ double stopwatch_t::elapsed()
double util::wall_time() { return wall_sw.elapsed(); }
double util::cpu_time() { return cpu_sw.elapsed(); }

// str_compare_ci ===========================================================

/// case-insensitive string comparison
bool util::str_compare_ci( const std::string& l,
const std::string& r )
{
Expand Down
94 changes: 94 additions & 0 deletions engine/sim/sc_progress_bar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// ==========================================================================
// Dedmonwakeen's Raid DPS/TPS Simulator.
// Send questions to [email protected]
// ==========================================================================

#include "simulationcraft.hpp"

progress_bar_t::progress_bar_t( sim_t& s ) :
sim( s ), steps( 20 ), updates( 100 ), interval( 0 ), start_time( 0 )
{
}

void progress_bar_t::init()
{
start_time = util::wall_time();
if ( sim.target_error > 0 )
{
interval = sim.analyze_error_interval;
}
else
{
interval = sim.work_queue -> size() / updates;
}
if ( interval == 0 )
{
interval = 1;
}
}

bool progress_bar_t::update( bool finished )
{
if ( sim.thread_index != 0 )
return false;
if ( !sim.report_progress )
return false;
if ( !sim.current_iteration )
return false;

if ( !finished )
{
if ( sim.current_iteration % interval )
{
return false;
}
}

auto progress = sim.progress();
auto pct = progress.pct();
if ( pct <= 0 )
return false;
if ( finished )
pct = 1.0;

size_t prev_size = status.size();

status = "[";
status.insert( 1, steps, '.' );
status += "]";

int length = static_cast<int>(steps * pct + 0.5);
for ( int i = 1; i < length + 1; ++i )
status[i] = '=';
if ( length > 0 )
status[length] = '>';

double current_time = util::wall_time() - start_time;
double total_time = current_time / pct;

int remaining_sec = int( total_time - current_time );
int remaining_min = remaining_sec / 60;
remaining_sec -= remaining_min * 60;

str::format( status, " %d/%d", finished ? progress.total_iterations : progress.current_iterations, progress.total_iterations );

if ( sim.target_error > 0 )
{
str::format( status, " Mean=%.0f Error=%.3f%%", sim.current_mean, sim.current_error );
}

if ( remaining_min > 0 )
{
str::format( status, " %dmin", remaining_min );
}

if ( remaining_sec > 0 )
{
str::format( status, " %dsec", remaining_sec );
}

if ( prev_size > status.size() )
status.insert( status.end(), ( prev_size - status.size() ), ' ' );

return true;
}
10 changes: 5 additions & 5 deletions engine/sim/sc_scaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ double scaling_t::progress( std::string& phase, std::string* detailed )
{
phase = "Baseline";
if ( ! baseline_sim ) return 0;
return baseline_sim -> progress( nullptr, nullptr, detailed );
return baseline_sim -> progress(detailed ).pct();
}

phase = "Scaling - ";
Expand All @@ -145,11 +145,11 @@ double scaling_t::progress( std::string& phase, std::string* detailed )

double divisor = num_scaling_stats * 2.0;

if ( ref_sim ) stat_progress += divisor * ref_sim -> progress();
if ( ref_sim2 ) stat_progress += divisor * ref_sim2 -> progress();
if ( ref_sim ) stat_progress += divisor * ref_sim -> progress().pct();
if ( ref_sim2 ) stat_progress += divisor * ref_sim2 -> progress().pct();

if ( delta_sim ) stat_progress += divisor * delta_sim -> progress();
if ( delta_sim2 ) stat_progress += divisor * delta_sim2 -> progress();
if ( delta_sim ) stat_progress += divisor * delta_sim -> progress().pct();
if ( delta_sim2 ) stat_progress += divisor * delta_sim2 -> progress().pct();

return stat_progress;
}
Expand Down
Loading

0 comments on commit 0159e92

Please sign in to comment.