Compare commits

..
1 Commits
Author SHA1 Message Date
wiesendsi102436 4880a9d2f4 fix: timers on Linux
On Linux the clock() function measures cpu time instead of wall time. This change uses the Apple code path for Linux.
2025-11-30 11:00:12 +01:00
26 changed files with 12 additions and 67 deletions
-62
View File
@@ -1,62 +0,0 @@
# ---> C
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
Startcode/doble_initial
Startcode/doble
Startcode/unitTests
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
# IDE folders
.vscode/
.idea/
# macOS
.DS_Store
Binary file not shown.
View File
View File
View File
+1 -1
View File
@@ -29,7 +29,7 @@ program_obj_files = stack.o bintree.o numbers.o timer.o highscore.o
doble : main.o $(program_obj_files) doble : main.o $(program_obj_files)
$(CC) $(FLAGS) $^ -o doble $(CC) $(FLAGS) $^ -o doble
$(program_obj_files): %.o: %.c $(program_obj_filesobj_files): %.o: %.c
$(CC) -c $(FLAGS) $^ -o $@ $(CC) -c $(FLAGS) $^ -o $@
# -------------------------- # --------------------------
View File
View File
View File
View File
+10 -3
View File
@@ -1,6 +1,12 @@
#include "timer.h" #include "timer.h"
#if __APPLE__ #ifdef __linux__
// Defines strict posix compliance for CLOCK_MONOTONIC
#define _POSIX_C_SOURCE 199309L
#include <time.h>
#endif
#if __APPLE__ || __linux__
#include <sys/time.h> #include <sys/time.h>
static struct timespec start = {0, 0}; static struct timespec start = {0, 0};
@@ -21,7 +27,8 @@ double stopTimer()
double measuredSeconds = (double)delta_us / 1000000.; double measuredSeconds = (double)delta_us / 1000000.;
if(start.tv_nsec > 0) { if (start.tv_nsec > 0)
{
start.tv_nsec = 0; start.tv_nsec = 0;
start.tv_sec = 0; start.tv_sec = 0;
} }
@@ -45,7 +52,7 @@ double stopTimer()
{ {
double measuredSeconds = (clock() - (double)startClocks) / CLOCKS_PER_SEC; double measuredSeconds = (clock() - (double)startClocks) / CLOCKS_PER_SEC;
if(startClocks > 0) if (startClocks > 0)
startClocks = 0; startClocks = 0;
else else
measuredSeconds = -1; measuredSeconds = -1;
View File