Skip to content

Commit 68da352

Browse files
committed
timer for windows and new cmake
1 parent 5ea67e2 commit 68da352

3 files changed

Lines changed: 92 additions & 39 deletions

File tree

‎.github/workflows/cmake.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ jobs:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
14-
os: [ubuntu-latest, macos-latest]
14+
os: [ubuntu-latest, macos-latest, windows-latest]
1515
build_type: [Release, Debug]
1616

1717
steps:
1818
- uses: actions/checkout@v3
1919

2020
- name: Configure CMake
21-
run: cmake -B build -S . -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
21+
run: cmake -B build -S . -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_VERBOSE_MAKEFILE=ON
2222

2323
- name: Build
2424
run: cmake --build build --config ${{ matrix.build_type }}
2525

2626
- name: Run tests
27-
run: ./build/all_tests
27+
run: ./build/all_tests --verbose

‎CMakeLists.txt‎

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@ else()
2020
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
2121
endif()
2222

23-
# Warning flags (always enabled)
24-
add_compile_options(
25-
-Wall # Enable most warnings
26-
-Wextra # Extra warnings
27-
-Wpedantic # Strict ISO C compliance
28-
-Wshadow # Warn about variable shadowing
29-
-Wformat=2 # Extra format string checks
30-
-Wcast-qual # Warn about cast that removes qualifiers
31-
-Wcast-align # Warn about pointer cast alignment issues
32-
-Wunused # Warn about unused variables/functions
33-
-Wdouble-promotion # Warn about float->double promotion
34-
-Wnull-dereference # Warn about null pointer dereference
35-
)
23+
# Warning flags (compiler-specific)
24+
if(MSVC)
25+
add_compile_options(/W4 /WX)
26+
else()
27+
add_compile_options(
28+
-Wall # Enable most warnings
29+
-Wextra # Extra warnings
30+
-Wpedantic # Strict ISO C compliance
31+
-Wshadow # Warn about variable shadowing
32+
-Wformat=2 # Extra format string checks
33+
-Wcast-qual # Warn about cast that removes qualifiers
34+
-Wcast-align # Warn about pointer cast alignment issues
35+
-Wunused # Warn about unused variables/functions
36+
-Wdouble-promotion # Warn about float->double promotion
37+
-Wnull-dereference # Warn about null pointer dereference
38+
)
39+
endif()
3640

3741
# Include directories
3842
include_directories(${PROJECT_SOURCE_DIR}/include)
@@ -43,15 +47,28 @@ file(GLOB_RECURSE SOURCES "src/*.c")
4347

4448
# Create core library
4549
add_library(dnlp_diff ${SOURCES})
46-
target_link_libraries(dnlp_diff m)
4750

48-
# Config-specific compile options
49-
target_compile_options(dnlp_diff PRIVATE
50-
$<$<CONFIG:Debug>:-g -O0>
51-
$<$<CONFIG:Release>:-O3 -DNDEBUG>
52-
$<$<CONFIG:RelWithDebInfo>:-O2 -g -DNDEBUG>
53-
$<$<CONFIG:MinSizeRel>:-Os -DNDEBUG>
54-
)
51+
# Link math library (Unix/Linux only)
52+
if(NOT MSVC)
53+
target_link_libraries(dnlp_diff m)
54+
endif()
55+
56+
# Config-specific compile options (compiler-specific)
57+
if(MSVC)
58+
target_compile_options(dnlp_diff PRIVATE
59+
$<$<CONFIG:Debug>:/Od /Zi>
60+
$<$<CONFIG:Release>:/O2 /DNDEBUG>
61+
$<$<CONFIG:RelWithDebInfo>:/O2 /Zi /DNDEBUG>
62+
$<$<CONFIG:MinSizeRel>:/Os /DNDEBUG>
63+
)
64+
else()
65+
target_compile_options(dnlp_diff PRIVATE
66+
$<$<CONFIG:Debug>:-g -O0>
67+
$<$<CONFIG:Release>:-O3 -DNDEBUG>
68+
$<$<CONFIG:RelWithDebInfo>:-O2 -g -DNDEBUG>
69+
$<$<CONFIG:MinSizeRel>:-Os -DNDEBUG>
70+
)
71+
endif()
5572

5673
# This is needed for clock_gettime on Linux without compiler extensions
5774
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")

‎include/utils/Timer.h‎

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,61 @@
1+
/*
2+
* Copyright 2025 Daniel Cederberg
3+
*
4+
* This file is part of the PSLP project (LP Presolver).
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
119
#ifndef TIMER_H
220
#define TIMER_H
321

4-
#include "time.h"
5-
22+
#if defined(_WIN32) || defined(_WIN64)
23+
#include <windows.h>
24+
typedef struct
25+
{
26+
LARGE_INTEGER start, end;
27+
} Timer;
28+
static inline void clock_gettime_monotonic(Timer *timer, int is_start)
29+
{
30+
if (is_start)
31+
{
32+
QueryPerformanceCounter(&timer->start);
33+
}
34+
else
35+
{
36+
QueryPerformanceCounter(&timer->end);
37+
}
38+
}
39+
static inline double get_elapsed_seconds(const Timer *timer)
40+
{
41+
LARGE_INTEGER freq;
42+
QueryPerformanceFrequency(&freq);
43+
return (double) (timer->end.QuadPart - timer->start.QuadPart) /
44+
(double) freq.QuadPart;
45+
}
46+
#define clock_gettime(CLOCK, PTR) \
47+
clock_gettime_monotonic((Timer *) (PTR), ((PTR) == &((Timer *) (PTR))->start))
48+
#define GET_ELAPSED_SECONDS(timer) get_elapsed_seconds(&(timer))
49+
#else
50+
#include <time.h>
651
typedef struct
752
{
853
struct timespec start, end;
954
} Timer;
1055

11-
// Macro to compute elapsed time in seconds
1256
#define GET_ELAPSED_SECONDS(timer) \
13-
(((timer).end.tv_sec - (timer).start.tv_sec) + \
14-
((double) ((timer).end.tv_nsec - (timer).start.tv_nsec) * 1e-9))
15-
16-
#define RUN_AND_TIME(func, timer, time_variable, result_var, ...) \
17-
do \
18-
{ \
19-
clock_gettime(CLOCK_MONOTONIC, &timer.start); \
20-
(result_var) = func(__VA_ARGS__); \
21-
clock_gettime(CLOCK_MONOTONIC, &timer.end); \
22-
(time_variable) += GET_ELAPSED_SECONDS(timer); \
23-
} while (0)
57+
((double) ((timer).end.tv_sec - (timer).start.tv_sec) + \
58+
(double) ((timer).end.tv_nsec - (timer).start.tv_nsec) / 1e9)
59+
#endif
2460

25-
#endif // TIMER_H
61+
#endif // TIMER_H

0 commit comments

Comments
 (0)