Skip to content

nc_perf does not build with MSVC (NETCDF_ENABLE_BENCHMARKS=ON fails on Windows) #3425

Description

@hyoklee

Environment Information

  • What platform are you using?
    • Windows (GitHub Actions windows-2025, MSVC 14.51.36231)
  • 32 and/or 64 bit?
    • 64-bit
  • What build system are you using?
    • cmake
  • Can you provide a sample netCDF file or C code to recreate the issue?
    • Not at this time (the existing nc_perf sources reproduce it)

Summary of Issue

nc_perf does not compile with MSVC, so -DNETCDF_ENABLE_BENCHMARKS=ON cannot
be used on Windows. The sources are POSIX-only by construction: none of the 23
.c files in nc_perf/ contains a single _WIN32 guard, and nearly all of
them use gettimeofday, getrusage, or <unistd.h> directly.

Two specific things block tst_chunks3, which is otherwise a useful portable
benchmark (it exercises contiguous / chunked / compressed access at a
configurable shape):

  1. nc_perf/tst_chunks3.c — the TIMING_DECLS / TIMING_START / TIMING_END
    macros are built on struct rusage and getrusage(RUSAGE_SELF, ...).
    MSVC provides neither, and the <sys/resource.h> include is already behind
    HAVE_SYS_RESOURCE_H, so the macros are left without a definition.

  2. nc_perf/tst_utils.c — includes <sys/time.h> unconditionally (for
    struct timeval, used by nc4_timeval_subtract). tst_chunks3 links this
    file, so it fails even if (1) is addressed:

    nc_perf\tst_utils.c(18,10): error C1083: Cannot open include file:
    'sys/time.h': No such file or directory
    

The rest of the directory fails the same way, e.g.:

nc_perf\bm_many_atts.c(17,10): error C1083: Cannot open include file: 'sys/time.h'
nc_perf\tst_mem.c(15,10):      error C1083: Cannot open include file: 'unistd.h'
nc_perf\bm_file.c(19,10):      error C1083: Cannot open include file: 'sys/time.h'
nc_perf\tst_wrf_reads.c(17,10):error C1083: Cannot open include file: 'sys/time.h'

Steps to reproduce the behavior

cmake -S netcdf-c -B build -A x64 -DNETCDF_ENABLE_BENCHMARKS=ON -DENABLE_HDF5=ON
cmake --build build --config Release

Note

I have a PR that addresses (1) and (2) only, which is enough to build and run
tst_chunks3 on Windows; the other nc_perf programs are untouched and remain
POSIX-only. Happy to extend it if you would rather see the whole directory
ported, or to close it if nc_perf is intentionally POSIX-only — in which case
it may be worth skipping add_subdirectory(nc_perf) on WIN32 so that
NETCDF_ENABLE_BENCHMARKS=ON fails early with a clear message instead of
partway through the build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions