aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-05-11 15:59:43 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-05-11 15:59:43 +0330
commitfe81eba1c232ab99bcfedf9546a82b06c796b086 (patch)
tree1ddf9d17f14a69c9cbe93cdbb1ef557f812c79d7 /src/utils
parent1a50974b834227190f7de3939db5689bb0702a34 (diff)
some clean ups
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/time.c16
-rw-r--r--src/utils/time.h8
2 files changed, 16 insertions, 8 deletions
diff --git a/src/utils/time.c b/src/utils/time.c
index 979a2c8..462ba02 100644
--- a/src/utils/time.c
+++ b/src/utils/time.c
@@ -3,8 +3,8 @@
#include <stdio.h>
#ifdef PRINT_STATISTICS
-struct timespec time_diff(struct timespec end, struct timespec start) {
- struct timespec temp;
+Time time_diff(Time end, Time start) {
+ Time temp;
if ((end.tv_nsec - start.tv_nsec) < 0) {
temp.tv_sec = end.tv_sec - start.tv_sec - 1;
temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
@@ -15,18 +15,24 @@ struct timespec time_diff(struct timespec end, struct timespec start) {
return temp;
}
-struct timespec time_add(struct timespec left, struct timespec right) {
- struct timespec result;
+Time time_add(Time left, Time right) {
+ Time result;
result.tv_nsec = left.tv_nsec + right.tv_nsec;
result.tv_sec = (left.tv_sec + right.tv_sec) + result.tv_nsec / 1000000000;
result.tv_nsec %= 1000000000;
return result;
}
-void time_print(struct timespec time) {
+void time_print(Time time) {
printf("%02ld:%02ld.%06ldus", time.tv_sec / 60, time.tv_sec % 60,
time.tv_nsec / 1000);
}
+
+Time get_time(){
+ Time t;
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t);
+ return t;
+}
#endif
diff --git a/src/utils/time.h b/src/utils/time.h
index 6d5f2f6..3e7cf41 100644
--- a/src/utils/time.h
+++ b/src/utils/time.h
@@ -2,6 +2,8 @@
#include <time.h>
-struct timespec time_diff(struct timespec end, struct timespec start);
-struct timespec time_add(struct timespec left, struct timespec right);
-void time_print(struct timespec time);
+typedef struct timespec Time;
+Time time_diff(Time end, Time start);
+Time time_add(Time left, Time right);
+void time_print(Time time);
+Time get_time();