Skip to content

Commit

Permalink
replace system_clock with high_resolution_clock
Browse files Browse the repository at this point in the history
  • Loading branch information
congyu711 committed Mar 26, 2024
1 parent 158d7d1 commit bbe540e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
12 changes: 6 additions & 6 deletions include/ode_solvers/implicit_midpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ struct ImplicitMidpointODESolver {
num_runs++;
pts partialDerivatives;
#ifdef TIME_KEEPING
start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
#endif
partialDerivatives = ham.DU(xs);
#ifdef TIME_KEEPING
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();
DU_duration += end - start;
#endif
xs = xs + partialDerivatives * (eta / 2);
Expand All @@ -119,12 +119,12 @@ struct ImplicitMidpointODESolver {
pts xs_old = xs;
pts xmid = (xs_prev + xs) / 2.0;
#ifdef TIME_KEEPING
start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
#endif
partialDerivatives = ham.approxDK(xmid, nu);

#ifdef TIME_KEEPING
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();
approxDK_duration += end - start;
#endif
xs = xs_prev + partialDerivatives * (eta);
Expand All @@ -144,11 +144,11 @@ struct ImplicitMidpointODESolver {
}
}
#ifdef TIME_KEEPING
start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
#endif
partialDerivatives = ham.DU(xs);
#ifdef TIME_KEEPING
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();
DU_duration += end - start;
#endif
xs = xs + partialDerivatives * (eta / 2);
Expand Down
36 changes: 18 additions & 18 deletions include/preprocess/crhmc/crhmc_problem.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,56 +330,56 @@ class crhmc_problem {
void simplify() {
#ifdef TIME_KEEPING
std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
#endif
rescale();
#ifdef TIME_KEEPING
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();
rescale_duration += end - start;
start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
#endif
splitDenseCols(options.maxNZ);
#ifdef TIME_KEEPING
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();
sparsify_duration += end - start;
start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
#endif
reorder();
#ifdef TIME_KEEPING
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();
reordering_duration += end - start;
#endif
int changed = 1;
while (changed) {
while (changed) {
changed = 0;
#ifdef TIME_KEEPING
start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
#endif
changed += remove_dependent_rows();
#ifdef TIME_KEEPING
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();
rm_rows_duration += end - start;
start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
#endif
changed += remove_fixed_variables();
#ifdef TIME_KEEPING
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();
rm_fixed_vars_duration += end - start;
start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
#endif
reorder();
#ifdef TIME_KEEPING
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();
reordering_duration += end - start;
#endif
}
#ifdef TIME_KEEPING
start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
#endif
changed += extract_collapsed_variables();
#ifdef TIME_KEEPING
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();
ex_collapsed_vars_duration += end - start;
#endif
}
Expand Down Expand Up @@ -546,7 +546,7 @@ class crhmc_problem {
simplify();
#ifdef TIME_KEEPING
std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
#endif
if (isempty_center) {
std::tie(center, std::ignore, std::ignore) =
Expand All @@ -555,7 +555,7 @@ class crhmc_problem {
}
shift_barrier(center);
#ifdef TIME_KEEPING
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();
shift_barrier_duration += end - start;
#endif
reorder();
Expand All @@ -564,7 +564,7 @@ class crhmc_problem {
// Recenter again and make sure it is feasible
VT hess;
#ifdef TIME_KEEPING
start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
#endif
std::tie(center, std::ignore, std::ignore, w_center) =
lewis_center<Crhmc_problem, SpMat, Opts, MT, VT, NT>(Asp, b, *this, options, center);
Expand All @@ -578,7 +578,7 @@ class crhmc_problem {
solver.solve((Tx *)input.data(), (Tx *)out.data());
center = center + (Asp.transpose() * out).cwiseProduct(Hinv);
#ifdef TIME_KEEPING
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();
lewis_center_duration += end - start;
#endif
if ((center.array() > barrier.ub.array()).any() ||
Expand Down
4 changes: 2 additions & 2 deletions include/random_walks/crhmc/crhmc_walk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ struct CRHMCWalk {
v_tilde = solver->get_state(1);
if (metropolis_filter) {
#ifdef TIME_KEEPING
start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
#endif
// Calculate initial Hamiltonian
H = solver->ham.hamiltonian(x, v);
Expand All @@ -188,7 +188,7 @@ struct CRHMCWalk {
H_tilde = solver->ham.hamiltonian(x_tilde, -v_tilde);

#ifdef TIME_KEEPING
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();
H_duration += end - start;
#endif
VT feasible = solver->ham.feasible(x_tilde,
Expand Down
8 changes: 4 additions & 4 deletions test/benchmarks_crhmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ double benchmark(std::string fileName) {
std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
std::cout << "CRHMC polytope preparation for " << fileName << std::endl;

start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
CrhmcProblem P = CrhmcProblem(input);
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();

std::cout << "Preparation completed in time, ";
std::chrono::duration<double> elapsed_seconds = end - start;
Expand All @@ -80,9 +80,9 @@ int main() {
std::cout << "CRHMC polytope preparation 100000 dimensional Cube "
<< std::endl;

start = std::chrono::system_clock::now();
start = std::chrono::high_resolution_clock::now();
CrhmcProblem P = CrhmcProblem(input);
end = std::chrono::system_clock::now();
end = std::chrono::high_resolution_clock::now();

std::cout << "Preparation completed in time, ";
std::chrono::duration<double> elapsed_seconds = end - start;
Expand Down

0 comments on commit bbe540e

Please sign in to comment.