Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Bench on Linux #581

Merged
merged 3 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions benchmarks/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
(name benchmark)
(public_name bench)
(enabled_if
(= %{system} macosx))
(or
(= %{system} macosx)
; or one of Linuxes (see https://github.com/ocaml/ocaml/issues/10613)
(= %{system} linux)
(= %{system} linux_elf)
(= %{system} elf)
(= %{system} linux_eabihf)
(= %{system} linux_eabi)))
(flags
(-open Syntax -open Compilerlibs406))
(foreign_stubs
(language c)
(names mac_osx_time))
(names time))
(libraries syntax compilerlibs406))

(data_only_dirs data)
16 changes: 0 additions & 16 deletions benchmarks/mac_osx_time.c

This file was deleted.

44 changes: 44 additions & 0 deletions benchmarks/time.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <caml/mlvalues.h>
#include <caml/alloc.h>

//
// Platform-specific includes
//
#if (defined(__MACH__) && defined(__APPLE__))
#include <mach/mach_time.h>
#elif defined(__linux__)
#include <time.h>
#endif

//
// Platform-specific globals
//
#if (defined(__MACH__) && defined(__APPLE__))
static mach_timebase_info_data_t info;
#endif

//
// Exported functions
//
CAMLprim value caml_mach_initialize(value unit) {
#if (defined(__MACH__) && defined(__APPLE__))
mach_timebase_info(&info);
#endif

return Val_unit;
}

CAMLprim value caml_mach_absolute_time(value unit) {
uint64_t result = 0;

#if (defined(__MACH__) && defined(__APPLE__))
uint64_t now = mach_absolute_time();
result = (now * info.numer) / info.denom;
#elif defined(__linux__)
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
result = now.tv_sec * 1000 + now.tv_nsec / 1000000;
#endif

return caml_copy_int64(result);
}