summaryrefslogtreecommitdiff
path: root/src/timefns.c
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2022-04-27 19:20:41 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-04-27 19:20:41 +0200
commit1110d7326f8b2b94f473244c5d2111324d06cd29 (patch)
treeb17c44e951b2b6db69a4c79f1203960338db9baa /src/timefns.c
parent92dcd7562cd9e00b0b0ef3ec4eb399f362b1d982 (diff)
downloademacs-1110d7326f8b2b94f473244c5d2111324d06cd29.tar.gz
Add new function current-cpu-time
* doc/lispref/os.texi (Time of Day): Document it. * src/timefns.c (Fcurrent_cpu_time): New function (bug#44674).
Diffstat (limited to 'src/timefns.c')
-rw-r--r--src/timefns.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/timefns.c b/src/timefns.c
index e7a2cd368e1..651e0760e83 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -1775,6 +1775,18 @@ if you need this older timestamp form. */)
return make_lisp_time (current_timespec ());
}
+#ifdef CLOCKS_PER_SEC
+DEFUN ("current-cpu-time", Fcurrent_cpu_time, Scurrent_cpu_time, 0, 0, 0,
+ doc: /* Return the current CPU time along with its resolution.
+The return value is a pair (CPU-TICKS . TICKS-PER-SEC).
+The CPU-TICKS counter can wrap around, so values cannot be meaningfully
+compared if too much time has passed between them. */)
+ (void)
+{
+ return Fcons (make_int (clock ()), make_int (CLOCKS_PER_SEC));
+}
+#endif
+
DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string,
0, 2, 0,
doc: /* Return the current local time, as a human-readable string.
@@ -2014,6 +2026,9 @@ syms_of_timefns (void)
DEFSYM (Qencode_time, "encode-time");
defsubr (&Scurrent_time);
+#ifdef CLOCKS_PER_SEC
+ defsubr (&Scurrent_cpu_time);
+#endif
defsubr (&Stime_convert);
defsubr (&Stime_add);
defsubr (&Stime_subtract);