aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-11-22 15:09:56 +0100
committerGitHub <noreply@github.com>2019-11-22 15:09:56 +0100
commit92b9285948f47a0191f6426276190550554c1d92 (patch)
tree54ba239065ac41606fcf86cd534b75d8848d8077
parent765a6317b83edf8ff5b3e1d8d63f46aa25f9d09c (diff)
parent9bcce78a59a200202b9e935ab59992964df848c4 (diff)
Merge pull request #11388 from vespa-engine/havardpe/chrono-guidelines
added time guidelines
-rw-r--r--vespalib/src/vespa/vespalib/util/time.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/util/time.h b/vespalib/src/vespa/vespalib/util/time.h
index bab410f040d..2f8ae0ae016 100644
--- a/vespalib/src/vespa/vespalib/util/time.h
+++ b/vespalib/src/vespa/vespalib/util/time.h
@@ -4,6 +4,25 @@
#include <chrono>
+// Guidelines:
+//
+// If you want to store a time duration or take it as a parameter,
+// prefer using vespalib::duration. This will allow automatic
+// conversion for most input duration types while avoiding templates.
+//
+// When passing a verbatim time duration to a function, assigning it
+// to a variable or comparing it to another time duration, prefer
+// using chrono literals. This will greatly improve code readability.
+//
+// Avoid code that depends on the resolution of time
+// durations. Specifically, do not use the count() function
+// directly. Using the utility functions supplied below will both make
+// your code safer (resolution independent) and simpler (avoiding
+// duration_cast).
+//
+// Prefer using steady_clock, only use system_clock if you absolutely
+// must have the system time.
+
using namespace std::literals::chrono_literals;
namespace vespalib {