A set of benchmarks to compare a new prototype MiniZinc implementation
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
3/*
4 * Main authors:
5 * Guido Tack <guido.tack@monash.edu>
6 */
7
8/* This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11
12#ifndef __MINIZINC_TIMER_HH__
13#define __MINIZINC_TIMER_HH__
14
15#include <chrono>
16#include <ctime>
17#include <iomanip>
18#include <ratio>
19#include <sstream>
20
21namespace MiniZinc {
22
23class Timer {
24protected:
25 std::chrono::steady_clock::time_point last;
26
27public:
28 /// Construct timer
29 Timer(void) : last(std::chrono::steady_clock::now()) {}
30 /// Reset timer
31 void reset(void) { last = std::chrono::steady_clock::now(); }
32 /// Return milliseconds since timer was last reset
33 long long int ms(void) const {
34 return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() -
35 last)
36 .count();
37 }
38 /// Return seconds since timer was last reset
39 double s(void) const {
40 return std::chrono::duration_cast<std::chrono::duration<double> >(
41 std::chrono::steady_clock::now() - last)
42 .count();
43 }
44 std::string stoptime(void) const {
45 std::ostringstream oss;
46 oss << std::setprecision(2) << std::fixed << s() << " s";
47 return oss.str();
48 }
49};
50
51} // namespace MiniZinc
52
53#endif