TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
timestamp.hpp
Go to the documentation of this file.
1// Copyright (c) 2017-2018 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2017-2018 Centre national de la recherche scientifique (CNRS)
3// Copyright (c) 2018 Simons Foundation
4// Copyright (c) 2017 Hugo U.R. Strand
5//
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You may obtain a copy of the License at
17// https://www.gnu.org/licenses/gpl-3.0.txt
18//
19// Authors: Hugo U. R. Strand, Nils Wentzell
20
25
26#pragma once
27
28#include "./timer.hpp"
29
30#include <chrono>
31#include <ctime>
32#include <iomanip>
33#include <sstream>
34#include <string>
35
36namespace triqs::utility {
37
42
47 std::string inline timestamp() {
48 std::ostringstream s;
49 auto now = std::chrono::system_clock::now();
50 std::time_t now_c = std::chrono::system_clock::to_time_t(now);
51 s << std::put_time(std::localtime(&now_c), "%H:%M:%S");
52 return s.str();
53 }
54
61 std::string inline hours_minutes_seconds_from_seconds(double sec) {
62 auto s = std::chrono::seconds{int(sec)};
63 auto h = std::chrono::duration_cast<std::chrono::hours>(s);
64 auto m = std::chrono::duration_cast<std::chrono::minutes>(s -= h);
65 s -= m;
66 std::ostringstream os;
67 os << std::setfill('0') << std::setw(2) << h.count() << ":" << std::setfill('0') << std::setw(2) << m.count() << ":" << std::setfill('0')
68 << std::setw(2) << s.count();
69 return os.str();
70 }
71
84 std::string inline estimate_time_left(int N, int n, timer &t) {
85 double eta = (N - 1 - n) * double(t) / (n + 1);
87 }
88
90
91} // namespace triqs::utility
Accumulating wall-clock timer based on std::chrono::high_resolution_clock.
Definition timer.hpp:39
std::string estimate_time_left(int N, int n, timer &t)
Linear extrapolation of the remaining time of a loop, formatted as HH:MM:SS.
Definition timestamp.hpp:84
std::string timestamp()
Current local time formatted as HH:MM:SS.
Definition timestamp.hpp:47
std::string hours_minutes_seconds_from_seconds(double sec)
Format an absolute number of seconds as HH:MM:SS.
Definition timestamp.hpp:61
A wall-clock timer that accumulates elapsed seconds across start/stop intervals.