diff --git a/src/common/macros.h b/src/common/macros.h
index 7f1bcd1888ace2430a85e95b1403d8ea51befc4b..04e0300dcc487ffa5daadc57eb96b83e504d8732 100644
--- a/src/common/macros.h
+++ b/src/common/macros.h
@@ -77,6 +77,16 @@ typedef enum {false, true} bool;
 #  define MIN(a,b) ((a) < (b) ? (a) : (b))
 #endif
 
+/*
+ * NOTE: ISO C doesn't guarantee that the following works, but POSIX does,
+ * as well as Windows and all reasonable systems. For maximum portability,
+ * one should do:
+ * SLURM_DIFFTIME(a,b) difftime((a), (b))
+ * but this code can show up high in the profile, so use the faster
+ * (in principle unportable but in practice fine) code below.
+ */
+#define SLURM_DIFFTIME(a,b) ((a) - (b))
+
 /* Avoid going over 32 bits for a constant to avoid warnings on some systems */
 #  define UINT64_SWAP_LE_BE(val)      ((uint64_t) (                           \
         (((uint64_t) (val) &                                                  \
diff --git a/src/plugins/select/cons_res/select_cons_res.c b/src/plugins/select/cons_res/select_cons_res.c
index 74a9dab58c0a46656edeb8227206b0985c7a2749..afe6ca3559ef84c64e42c43288a805108b93aa30 100644
--- a/src/plugins/select/cons_res/select_cons_res.c
+++ b/src/plugins/select/cons_res/select_cons_res.c
@@ -453,7 +453,7 @@ static int _cr_job_list_sort(void *x, void *y)
 {
 	struct job_record *job1_ptr = (struct job_record *) x;
 	struct job_record *job2_ptr = (struct job_record *) y;
-	return (int) difftime(job1_ptr->end_time, job2_ptr->end_time);
+	return (int) SLURM_DIFFTIME(job1_ptr->end_time, job2_ptr->end_time);
 }
 
 
diff --git a/src/plugins/select/linear/select_linear.c b/src/plugins/select/linear/select_linear.c
index 7d0a2380cd379930ea238c2583ffb3f829556414..149f0d428ab6d6b7a7a9f9693af5cb95f35d85f9 100644
--- a/src/plugins/select/linear/select_linear.c
+++ b/src/plugins/select/linear/select_linear.c
@@ -2628,7 +2628,7 @@ static int  _cr_job_list_sort(void *x, void *y)
 {
 	struct job_record *job1_ptr = (struct job_record *) x;
 	struct job_record *job2_ptr = (struct job_record *) y;
-	return (int) difftime(job1_ptr->end_time, job2_ptr->end_time);
+	return (int) SLURM_DIFFTIME(job1_ptr->end_time, job2_ptr->end_time);
 }
 
 /*
diff --git a/src/plugins/select/serial/select_serial.c b/src/plugins/select/serial/select_serial.c
index 09c005410a396a51717e236ac6272e091f7ebce6..f22ac0fd249c590b18ce6a75de0e7600c9d9df3c 100644
--- a/src/plugins/select/serial/select_serial.c
+++ b/src/plugins/select/serial/select_serial.c
@@ -385,7 +385,7 @@ static int _cr_job_list_sort(void *x, void *y)
 {
 	struct job_record *job1_ptr = (struct job_record *) x;
 	struct job_record *job2_ptr = (struct job_record *) y;
-	return (int) difftime(job1_ptr->end_time, job2_ptr->end_time);
+	return (int) SLURM_DIFFTIME(job1_ptr->end_time, job2_ptr->end_time);
 }