Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/galsim/Std.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
#include <map>

#ifdef _WIN32
// Suppress Windows.h's ``min``/``max`` macros which clash with std::min/std::max
// (and Eigen's templated members). Set this before the include even though the
// MSVC build also passes ``/DNOMINMAX`` -- belt and suspenders for direct includes.
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>
#else
#include <sys/time.h>
Expand Down
16 changes: 8 additions & 8 deletions include/galsim/Stopwatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@
#ifndef GalSim_Stopwatch_H
#define GalSim_Stopwatch_H

#include <sys/time.h>
#include <chrono>

namespace galsim {

class Stopwatch
{
private:
typedef std::chrono::steady_clock clock_type;
double seconds;
struct timeval tpStart;
clock_type::time_point tpStart;
bool running;
public:
Stopwatch() : seconds(0.), running(false) {}

void start() { gettimeofday(&tpStart, NULL); running=true; }
void start() { tpStart = clock_type::now(); running = true; }

void stop()
{
if (!running) return;
struct timeval tp;
gettimeofday(&tp, NULL);
seconds += (tp.tv_sec - tpStart.tv_sec)
+ 1e-6*(tp.tv_usec - tpStart.tv_usec);
auto tp = clock_type::now();
std::chrono::duration<double> dt = tp - tpStart;
seconds += dt.count();
running = false;
}
void reset() { seconds=0.; running=false; }
void reset() { seconds = 0.; running = false; }
operator double() const { return seconds; }
};

Expand Down
Loading