diff options
-rw-r--r-- | B0.ml | 51 | ||||
-rw-r--r-- | BRZO | 3 | ||||
-rw-r--r-- | CHANGES.md | 17 | ||||
-rw-r--r-- | README.md | 28 | ||||
-rw-r--r-- | _tags | 21 | ||||
-rwxr-xr-x | build-tests | 15 | ||||
-rw-r--r-- | debian/changelog | 10 | ||||
-rw-r--r-- | debian/control | 4 | ||||
-rw-r--r-- | debian/libmtime-ocaml-dev.install.in | 7 | ||||
-rw-r--r-- | debian/libmtime-ocaml.install.in | 2 | ||||
-rw-r--r-- | doc/index.mld | 24 | ||||
-rw-r--r-- | myocamlbuild.ml | 42 | ||||
-rw-r--r-- | opam | 45 | ||||
-rw-r--r-- | pkg/META | 30 | ||||
-rwxr-xr-x | pkg/pkg.ml | 22 | ||||
-rw-r--r-- | src-clock/libmtime_clock_stubs.clib (renamed from src-os/libmtime_clock_stubs.clib) | 0 | ||||
-rw-r--r-- | src-clock/mtime_clock.ml (renamed from src-os/mtime_clock.ml) | 0 | ||||
-rw-r--r-- | src-clock/mtime_clock.mli (renamed from src-os/mtime_clock.mli) | 16 | ||||
-rw-r--r-- | src-clock/mtime_clock.mllib (renamed from src-os/mtime_clock.mllib) | 0 | ||||
-rw-r--r-- | src-clock/mtime_clock_stubs.c (renamed from src-os/mtime_clock_stubs.c) | 3 | ||||
-rw-r--r-- | src-clock/runtime.js | 93 | ||||
-rw-r--r-- | src-jsoo/mtime_clock.ml | 98 | ||||
-rw-r--r-- | src-jsoo/mtime_clock.mli | 125 | ||||
-rw-r--r-- | src-jsoo/mtime_clock.mllib | 1 | ||||
-rw-r--r-- | src/mtime.ml | 52 | ||||
-rw-r--r-- | src/mtime.mli | 146 | ||||
-rw-r--r-- | src/mtime_clock.mli | 16 | ||||
-rw-r--r-- | src/mtime_top_init.ml | 4 | ||||
-rw-r--r-- | test-jsoo/test_jsoo.html | 48 | ||||
-rw-r--r-- | test-jsoo/test_jsoo.ml | 42 | ||||
-rw-r--r-- | test-jsoo/test_node.ml | 22 | ||||
-rw-r--r-- | test-jsoo/tests.ml | 275 | ||||
-rw-r--r-- | test-os/min_os.ml | 15 | ||||
-rw-r--r-- | test/min_clock.ml | 23 | ||||
-rw-r--r-- | test/test.ml (renamed from test-os/test.ml) | 0 | ||||
-rw-r--r-- | test/tests.ml (renamed from test-os/tests.ml) | 3 |
36 files changed, 420 insertions, 883 deletions
@@ -5,12 +5,11 @@ open Result.Syntax (* OCaml library names *) let compiler_libs_toplevel = B0_ocaml.libname "compiler-libs.toplevel" -let js_of_ocaml = B0_ocaml.libname "js_of_ocaml" let mtime = B0_ocaml.libname "mtime" let mtime_top = B0_ocaml.libname "mtime.top" +let mtime_clock = B0_ocaml.libname "mtime.clock" let mtime_clock_os = B0_ocaml.libname "mtime.clock.os" -let mtime_clock_jsoo = B0_ocaml.libname "mtime.clock.jsoo" (* Libraries *) @@ -24,27 +23,43 @@ let mtime_top = let requires = [compiler_libs_toplevel] in B0_ocaml.lib mtime_top ~doc:"The mtime.top library" ~srcs ~requires -let mtime_clock_os_lib = - let srcs = Fpath.[`Dir (v "src-os") ] in +let mtime_clock = + let srcs = Fpath.[`File (v "src/mtime_clock.mli")] in let requires = [mtime] in - B0_ocaml.lib mtime_clock_os ~doc:"The mtime clock OS library" ~srcs ~requires + let doc = "The mtime.clock interface library" in + B0_ocaml.lib mtime_clock ~doc ~srcs ~requires -let mtime_clock_jsoo_lib = - let srcs = Fpath.[`Dir (v "src-jsoo") ] in - let requires = [mtime; js_of_ocaml] in - let doc = "The mtime clock JSOO library" in - B0_ocaml.lib mtime_clock_jsoo ~doc ~srcs ~requires +let mtime_clock_os_lib = + let srcs = Fpath.[`Dir (v "src-clock") ] in + let requires = [mtime] in + let doc = "The mtime.clock library (including JavaScript support)" in + B0_ocaml.lib mtime_clock_os ~doc ~srcs ~requires (* Tests *) let test = - let srcs = Fpath.[`File (v "test-os/test.ml"); - `File (v "test-os/tests.ml")] - in + let srcs = Fpath.[`File (v "test/test.ml"); `File (v "test/tests.ml")] in let meta = B0_meta.(empty |> tag test) in let requires = [ mtime; mtime_clock_os ] in B0_ocaml.exe "test" ~doc:"Test suite" ~srcs ~meta ~requires +let min_clock = + let srcs = Fpath.[`File (v "test/min_clock.ml") ] in + let meta = B0_meta.(empty |> tag test) in + let requires = [mtime; mtime_clock_os] in + let doc = "Minimal clock example" in + B0_ocaml.exe "min-clock" ~doc ~srcs ~meta ~requires + +(* FIXME b0 this forces the whole build to bytecode which is not + what we want. +let min_clock_jsoo = + let srcs = Fpath.[`File (v "test/min_clock.ml") ] in + let meta = B0_meta.(empty |> tag test) in + let meta = B0_jsoo.meta ~requires:[mtime; mtime_clock_os] ~meta () in + let doc = "Minimal clock example" in + B0_jsoo.web "min-clock-jsoo" ~doc ~srcs ~meta +*) + (* Packs *) let default = @@ -61,18 +76,14 @@ let default = |> add issues "https://github.com/dbuenzli/mtime/issues" |> add description_tags ["time"; "monotonic"; "system"; "org:erratique"] - |> add B0_opam.Meta.depopts ["js_of_ocaml", ""] - |> add B0_opam.Meta.conflicts - [ "js_of_ocaml", {|<= "3.3.0"|}] |> add B0_opam.Meta.depends - [ "ocaml", {|>= "4.03.0"|}; + [ "ocaml", {|>= "4.08.0"|}; "ocamlfind", {|build|}; - "ocamlbuild", {|build|}; + "ocamlbuild", {|build & != "0.9.0"|}; "topkg", {|build & >= "1.0.3"|}; ] |> add B0_opam.Meta.build - {|[["ocaml" "pkg/pkg.ml" "build" "--dev-pkg" "%{dev}%" - "--with-js_of_ocaml" "%{js_of_ocaml:installed}%"]]|} + {|[["ocaml" "pkg/pkg.ml" "build" "--dev-pkg" "%{dev}%"]]|} in B0_pack.v "default" ~doc:"mtime package" ~meta ~locked:true @@ B0_unit.list () @@ -1,2 +1 @@ -(srcs-x pkg test-jsoo test-os myocamlbuild.ml - src/mtime_top.ml src/mtime_top_init.ml)
\ No newline at end of file +(srcs-x myocamlbuild.ml pkg test src/mtime_top.ml src/mtime_top_init.ml)
\ No newline at end of file @@ -1,3 +1,20 @@ +v1.4.0 2022-02-17 La Forclaz (VS) +--------------------------------- + +* Change the `js_of_ocaml` strategy for `Mtime_clock`'s JavaScript + implementation. Primitives of `mtime.clock.os` are now implemented + in pure JavaScript and linked by `js_of_ocaml`. This means that the + `mtime.clock.jsoo` library no longer exists, simply link against + `mtime.clock.os` instead. Thanks to Hugo Heuzard for suggesting and + implementing this. + +* Add `Mtime.{min,max}_stamp`. +* Add durations `Mtime.Span.{ns,us,ms,s,min,hour,day,year}` and + the `Mtime.Span.(*)` operator (#28). +* Deprecate `Mtime.s_to_*` and `Mtime.*_to_s` floating point constants (#28). +* Require OCaml >= 4.08. +* Allow compiling with MSVC compiler. Thanks to Jonah Beckford for the patch. + v1.3.0 2021-10-20 Zagreb ------------------------ @@ -1,6 +1,6 @@ Mtime — Monotonic wall-clock time for OCaml -------------------------------------------------------------------------------- -v1.3.0 +=========================================== +v1.4.0 Mtime has platform independent support for monotonic wall-clock time in pure OCaml. This time increases monotonically and is not subject to @@ -10,40 +10,30 @@ represent nanosecond precision timestamps and time spans. The additional Mtime_clock library provide access to a system monotonic clock. -Mtime has a no dependency. Mtime_clock depends on your system library. -The optional JavaScript support depends on [js_of_ocaml][jsoo]. Mtime -and its libraries are distributed under the ISC license. - -[jsoo]: http://ocsigen.org/js_of_ocaml/ +Mtime has a no dependency. Mtime_clock depends on your system library +or JavaScript runtime system. Mtime and its libraries are distributed +under the ISC license. Home page: http://erratique.ch/software/mtime -## Installation +# Installation Mtime can be installed with `opam`: opam install mtime - opam install js_of_ocaml mtime # mtime with jsoo support If you don't use `opam` consult the [`opam`](opam) file for build instructions. -## Documentation +# Documentation The documentation and API reference is automatically generated from the source interfaces. It can be consulted [online][doc] or via `odig doc mtime`. -[doc]: http://erratique.ch/software/mtime/doc - +[doc]: http://erratique.ch/software/mtime/doc/ -## Sample programs +# Sample programs If you installed mtime with `opam` sample programs are located in the directory `opam config var mtime:doc`. - -In the distribution sample programs and tests are located in the -`test*` directories. They can be built and run with: - - topkg build --tests true && topkg test - @@ -1,22 +1,11 @@ true : bin_annot, safe_string -# Ideally we should not have this and use_mtime -# would give us the right link order, see -# https://github.com/ocaml/ocamlbuild/issues/122 -<src> : include +<_b0> : -traverse +<src> : include <src/mtime_top*> : package(compiler-libs.toplevel) -<src-os/mtime_clock.{cma,cmxa}> : record_mtime_clock_os_stubs -<src-os/mtime_clock.cmxs> : link_mtime_clock_os_stubs - -# use_mtime is missing, see above -<test-os/*> : use_mtime_clock_os -<test-os/test.byte> : custom - -<{src,test}-jsoo/*> : package(js_of_ocaml) - -# use_mtime is missing, see above -<test-jsoo/*> : use_mtime_clock_jsoo +<src-clock/mtime_clock.{cma,cmxa}> : record_mtime_clock_os_stubs +<src-clock/mtime_clock.cmxs> : link_mtime_clock_os_stubs -<_b0> : -traverse
\ No newline at end of file +<test/*> : use_mtime, use_mtime_clock_os
\ No newline at end of file diff --git a/build-tests b/build-tests deleted file mode 100755 index 66e7d99..0000000 --- a/build-tests +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -# Work around https://github.com/ocaml/ocamlbuild/issues/122 - -set -e - -OCAMLBUILD=${OCAMLBUILD:="ocamlbuild -tag debug -classic-display \ - -no-links -use-ocamlfind" } - -$OCAMLBUILD -I src -I src-jsoo \ - test-jsoo/test_node.js test-jsoo/test_jsoo.js test-jsoo/test_jsoo.html - -$OCAMLBUILD -I src -I src-os \ - test-os/min_os.byte test-os/min_os.native \ - test-os/test.byte test-os/test.native diff --git a/debian/changelog b/debian/changelog index 4068674..7a2cef7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,13 @@ +ocaml-mtime (1.4.0-1) unstable; urgency=medium + + [ Stéphane Glondu ] + * New upstream release + + [ Debian Janitor ] + * Use secure URI in Homepage field. + + -- Stéphane Glondu <glondu@debian.org> Mon, 21 Feb 2022 11:27:11 +0100 + ocaml-mtime (1.3.0-1) unstable; urgency=medium * Initial release (Closes: #1000394) diff --git a/debian/control b/debian/control index fd5b23e..3d6fbf7 100644 --- a/debian/control +++ b/debian/control @@ -6,7 +6,7 @@ Uploaders: Stéphane Glondu <glondu@debian.org> Build-Depends: debhelper-compat (= 13), - ocaml-nox, + ocaml, ocaml-findlib, ocamlbuild, libjs-of-ocaml-dev, @@ -15,7 +15,7 @@ Build-Depends: dh-ocaml Standards-Version: 4.6.0 Rules-Requires-Root: no -Homepage: http://erratique.ch/software/mtime +Homepage: https://erratique.ch/software/mtime Vcs-Git: https://salsa.debian.org/ocaml-team/ocaml-mtime.git Vcs-Browser: https://salsa.debian.org/ocaml-team/ocaml-mtime diff --git a/debian/libmtime-ocaml-dev.install.in b/debian/libmtime-ocaml-dev.install.in index 6ff6b2e..bef522b 100644 --- a/debian/libmtime-ocaml-dev.install.in +++ b/debian/libmtime-ocaml-dev.install.in @@ -12,3 +12,10 @@ OPT: @OCamlStdlibDir@/*/*.a OPT: @OCamlStdlibDir@/*/*/*.cmx OPT: @OCamlStdlibDir@/*/*/*.cmxa OPT: @OCamlStdlibDir@/*/*/*.a +@OCamlStdlibDir@/*/*/*/*.mli +@OCamlStdlibDir@/*/*/*/*.cmi +@OCamlStdlibDir@/*/*/*/*.cmt* +@OCamlStdlibDir@/*/*/*/*.a +@OCamlStdlibDir@/*/*/*/*.js +OPT: @OCamlStdlibDir@/*/*/*/*.cmx +OPT: @OCamlStdlibDir@/*/*/*/*.cmxa diff --git a/debian/libmtime-ocaml.install.in b/debian/libmtime-ocaml.install.in index 833a888..db51abe 100644 --- a/debian/libmtime-ocaml.install.in +++ b/debian/libmtime-ocaml.install.in @@ -4,3 +4,5 @@ OPT: @OCamlStdlibDir@/*/*.cmxs @OCamlStdlibDir@/*/*/*.cma OPT: @OCamlStdlibDir@/*/*/*.cmxs +@OCamlStdlibDir@/*/*/*/*.cma +OPT: @OCamlStdlibDir@/*/*/*/*.cmxs diff --git a/doc/index.mld b/doc/index.mld index 4dc6af6..eea17fe 100644 --- a/doc/index.mld +++ b/doc/index.mld @@ -1,11 +1,19 @@ -{0 Mtime {%html: <span class="version">v1.3.0</span>%}} +{0 Mtime {%html: <span class="version">v1.4.0</span>%}} -Mtime has platform independent support for monotonic wall-clock time -in pure OCaml. +Mtime has platform independent support for monotonic wall-clock time. +This time increases monotonically and is not subject to operating +system calendar time adjustments. The library has types to represent +nanosecond precision timestamps and time spans. -{1:api API} +{!Mtime_clock} provides acces to {{!Mtime_clock.platform_support}a +monotonic system clock} and its resolution (if available). -{!modules: -Mtime -Mtime_clock -} +{1:mtime Library [mtime]} + +{!modules: Mtime} + +{1:mtime_clock Library [mtime.clock.os]} + +{!modules: Mtime_clock} + +Also use this library for compiling to JavaScript. diff --git a/myocamlbuild.ml b/myocamlbuild.ml index a1d9bab..689ecd0 100644 --- a/myocamlbuild.ml +++ b/myocamlbuild.ml @@ -1,27 +1,13 @@ - open Ocamlbuild_plugin open Command let os = try Sys.getenv "MTIME_OS" with -| Not_found -> - Ocamlbuild_pack.My_unix.run_and_read "uname -s" +| Not_found -> Ocamlbuild_pack.My_unix.run_and_read "uname -s" let system_support_lib = match os with | "Linux\n" -> [A "-cclib"; A "-lrt"] | _ -> [] -let js_rule () = - let dep = "%.byte" in - let prod = "%.js" in - let f env _ = - let dep = env dep in - let prod = env prod in - let tags = tags_of_pathname prod ++ "js_of_ocaml" in - Cmd (S [A "js_of_ocaml"; T tags; A "-o"; - Px prod; P dep]) - in - rule "js_of_ocaml: .byte -> .js" ~dep ~prod f - let lib s = match !Ocamlbuild_plugin.Options.ext_lib with | "" -> s ^ ".a" @@ -30,7 +16,6 @@ let lib s = let () = dispatch begin function | After_rules -> - js_rule (); (* mtime *) @@ -38,24 +23,21 @@ let () = (* mtime-clock-os *) - dep ["record_mtime_clock_os_stubs"] ["src-os/libmtime_clock_stubs.a"]; - flag_and_dep - ["link"; "ocaml"; "link_mtime_clock_os_stubs"] - (P (lib "src-os/libmtime_clock_stubs")); + flag_and_dep ["link"; "ocaml"; "link_mtime_clock_os_stubs"] + (P (lib "src-clock/libmtime_clock_stubs")); + + dep ["record_mtime_clock_os_stubs"] + [lib "src-clock/libmtime_clock_stubs"]; + flag ["library"; "ocaml"; "byte"; "record_mtime_clock_os_stubs"] (S ([A "-dllib"; A "-lmtime_clock_stubs"] @ system_support_lib)); - flag ["library"; "ocaml"; (* byte and native *) - "record_mtime_clock_os_stubs"] + flag ["library"; "ocaml"; "record_mtime_clock_os_stubs"] (* byt + nat *) (S ([A "-cclib"; A "-lmtime_clock_stubs"] @ system_support_lib)); - ocaml_lib ~tag_name:"use_mtime_clock_os" - ~dir:"src-os" "src-os/mtime_clock"; - flag ["link"; "ocaml"; "use_mtime_clock_os"] - (S [A "-ccopt"; A "-Lsrc-os"]); - - (* mtime-jsoo *) - ocaml_lib ~tag_name:"use_mtime_clock_jsoo" ~dir:"src-jsoo" - "src-jsoo/mtime_clock"; + ocaml_lib ~tag_name:"use_mtime_clock_os" ~dir:"src-clock" + "src-clock/mtime_clock"; + flag ["link"; "ocaml"; "use_mtime_clock_os"] + (S [A "-ccopt"; A "-Lsrc-clock"]); | _ -> () end @@ -1,24 +1,8 @@ -version: "1.3.0" +version: "1.4.0" opam-version: "2.0" name: "mtime" -synopsis: """Monotonic wall-clock time for OCaml""" -maintainer: ["Daniel Bünzli <daniel.buenzl i@erratique.ch>"] -authors: ["The mtime programmers"] -homepage: "https://erratique.ch/software/mtime" -doc: "https://erratique.ch/software/mtime/doc/" -dev-repo: "git+https://erratique.ch/repos/mtime.git" -bug-reports: "https://github.com/dbuenzli/mtime/issues" -license: ["ISC"] -tags: ["time" "monotonic" "system" "org:erratique"] -depends: ["ocaml" {>= "4.03.0"} - "ocamlfind" {build} - "ocamlbuild" {build} - "topkg" {build & >= "1.0.3"}] -depopts: ["js_of_ocaml"] -conflicts: ["js_of_ocaml" {<= "3.3.0"}] -build: [["ocaml" "pkg/pkg.ml" "build" "--dev-pkg" "%{dev}%" - "--with-js_of_ocaml" "%{js_of_ocaml:installed}%"]] -description: """ +synopsis: "Monotonic wall-clock time for OCaml" +description: """\ Mtime has platform independent support for monotonic wall-clock time in pure OCaml. This time increases monotonically and is not subject to operating system calendar time adjustments. The library has types to @@ -27,10 +11,23 @@ represent nanosecond precision timestamps and time spans. The additional Mtime_clock library provide access to a system monotonic clock. -Mtime has a no dependency. Mtime_clock depends on your system library. -The optional JavaScript support depends on [js_of_ocaml][jsoo]. Mtime -and its libraries are distributed under the ISC license. - -[jsoo]: http://ocsigen.org/js_of_ocaml/ +Mtime has a no dependency. Mtime_clock depends on your system library +or JavaScript runtime system. Mtime and its libraries are distributed +under the ISC license. Home page: http://erratique.ch/software/mtime""" +maintainer: "Daniel Bünzli <daniel.buenzl i@erratique.ch>" +authors: "The mtime programmers" +license: "ISC" +tags: ["time" "monotonic" "system" "org:erratique"] +homepage: "https://erratique.ch/software/mtime" +doc: "https://erratique.ch/software/mtime/doc/" +bug-reports: "https://github.com/dbuenzli/mtime/issues" +depends: [ + "ocaml" {>= "4.08.0"} + "ocamlfind" {build} + "ocamlbuild" {build & != "0.9.0"} + "topkg" {build & >= "1.0.3"} +] +build: ["ocaml" "pkg/pkg.ml" "build" "--dev-pkg" "%{dev}%"] +dev-repo: "git+https://erratique.ch/repos/mtime.git" @@ -1,5 +1,5 @@ description = "Monotonic wall-clock time for OCaml" -version = "1.3.0" +version = "1.4.0" requires = "" archive(byte) = "mtime.cma" archive(native) = "mtime.cmxa" @@ -8,8 +8,9 @@ plugin(native) = "mtime.cmxs" package "top" ( description = "Mtime toplevel support" - version = "1.3.0" + version = "1.4.0" requires = "mtime" + directory = "top" archive(byte) = "mtime_top.cma" archive(native) = "mtime_top.cmxa" plugin(byte) = "mtime_top.cma" @@ -17,29 +18,20 @@ package "top" ( ) package "clock" ( - description = "Monotonic time clocks" - version = "1.3.0" + description = "Monotonic time clock interface" + version = "1.4.0" requires = "" + directory = "clock" package "os" ( - directory="os" - description = "Mtime_clock for native OS" - version = "1.3.0" + description = "Mtime_clock for your platform (including JavaScript)" + version = "1.4.0" requires = "mtime" + directory = "os" archive(byte) = "mtime_clock.cma" archive(native) = "mtime_clock.cmxa" plugin(byte) = "mtime_clock.cma" plugin(native) = "mtime_clock.cmxs" - exists_if = "mtime_clock.cma" ) - - package "jsoo" ( - directory="jsoo" - description = "Mtime_clock for js_of_ocaml" - version = "1.3.0" - requires = "mtime js_of_ocaml" - archive(byte) = "mtime_clock.cma" - archive(native) = "mtime_clock.cmxa" - plugin(byte) = "mtime_clock.cma" - plugin(native) = "mtime_clock.cmxs" - exists_if = "mtime_clock.cma" ) + linkopts(javascript) = "+mtime.clock.os/runtime.js" + exists_if = "mtime_clock.cma") ) @@ -3,24 +3,14 @@ #require "topkg" open Topkg -let jsoo = Conf.with_pkg "js_of_ocaml" - let () = Pkg.describe "mtime" @@ fun c -> - let jsoo = Conf.value c jsoo in Ok [ Pkg.mllib "src/mtime.mllib"; - Pkg.mllib ~api:[] "src/mtime_top.mllib"; + Pkg.mllib ~api:[] "src/mtime_top.mllib" ~dst_dir:"top/"; Pkg.lib "src/mtime_top_init.ml"; + Pkg.lib ~exts:Exts.interface "src/mtime_clock" ~dst:"clock/"; + Pkg.mllib "src-clock/mtime_clock.mllib" ~dst_dir:"clock/os/"; + Pkg.clib "src-clock/libmtime_clock_stubs.clib" ~lib_dst_dir:"clock/os/"; + Pkg.lib "src-clock/runtime.js" ~dst:"clock/os/"; Pkg.doc "doc/index.mld" ~dst:"odoc-pages/index.mld"; - Pkg.mllib "src-os/mtime_clock.mllib" ~dst_dir:"os/"; - Pkg.clib "src-os/libmtime_clock_stubs.clib" ~lib_dst_dir:"os/"; - Pkg.mllib ~cond:jsoo "src-jsoo/mtime_clock.mllib" ~dst_dir:"jsoo"; -(* Unable to find a way to convince ocamlbuild to make these work - because of https://github.com/ocaml/ocamlbuild/issues/122 - - Pkg.test "test-os/min_os"; - Pkg.test "test-os/test"; - Pkg.test ~run:false ~cond:jsoo ~auto:false "test-jsoo/test_jsoo.js"; - Pkg.test ~run:false ~cond:jsoo ~auto:false "test-jsoo/test_jsoo.html"; -*) - Pkg.doc "test-os/min_os.ml" ] + Pkg.doc "test/min_clock.ml"; ] diff --git a/src-os/libmtime_clock_stubs.clib b/src-clock/libmtime_clock_stubs.clib index 3ea2529..3ea2529 100644 --- a/src-os/libmtime_clock_stubs.clib +++ b/src-clock/libmtime_clock_stubs.clib diff --git a/src-os/mtime_clock.ml b/src-clock/mtime_clock.ml index 1a6219c..1a6219c 100644 --- a/src-os/mtime_clock.ml +++ b/src-clock/mtime_clock.ml diff --git a/src-os/mtime_clock.mli b/src-clock/mtime_clock.mli index 72c78f2..d35b9a0 100644 --- a/src-os/mtime_clock.mli +++ b/src-clock/mtime_clock.mli @@ -14,11 +14,7 @@ {{!Mtime_clock.counters}counters}. Consult important information about {{!err}error handling} - and {{!platform_support}platform support}. - - Concrete implementation of this interfaces are provided by the - [mtime.clock.os] and [mtime.clock.jsoo] packages against which you - should compile depending on your target. *) + and {{!platform_support}platform support}. *) (** {1:clock Monotonic clock} *) @@ -26,13 +22,13 @@ val elapsed : unit -> Mtime.span (** [elapsed ()] is the monotonic time span elapsed since the beginning of the program. - @raise Sys_error see {{!err}error handling} *) + Raises {!Sys_error}, see {{!err}error handling} *) val now : unit -> Mtime.t (** [now ()] is the current system-relative monotonic timestamp. Its absolute value is meaningless. - @raise Sys_error see {{!err}error handling} *) + Raises {!Sys_error}, see {{!err}error handling} *) val period : unit -> Mtime.span option (** [period ()] is the clock's period as a monotonic time span (if @@ -46,7 +42,7 @@ type counter val counter : unit -> counter (** [counter ()] is a counter counting from now on. - @raise Sys_error see {{!err}error handling} *) + Raises {!Sys_error}, see {{!err}error handling} *) val count : counter -> Mtime.span (** [count c] is the monotonic time span elapsed since [c] was created. *) @@ -57,14 +53,14 @@ val elapsed_ns : unit -> int64 (** [elapsed_ns ()] is the {e unsigned} 64-bit integer nanosecond monotonic time span elapsed since the beginning of the program. - @raise Sys_error see {{!err}error handling} *) + Raises {!Sys_error}, see {{!err}error handling} *) val now_ns : unit -> int64 (** [now_ns ()] is an {e unsigned} 64-bit integer nanosecond system-relative monotonic timestamp. The absolute value is meaningless. - @raise Sys_error see {{!err}error handling} *) + Raises {!Sys_error}, see {{!err}error handling} *) val period_ns : unit -> int64 option (** [period_ns ()] is the clock's period as an {e unsigned} 64-bit diff --git a/src-os/mtime_clock.mllib b/src-clock/mtime_clock.mllib index b969023..b969023 100644 --- a/src-os/mtime_clock.mllib +++ b/src-clock/mtime_clock.mllib diff --git a/src-os/mtime_clock_stubs.c b/src-clock/mtime_clock_stubs.c index 918837a..93bdfc1 100644 --- a/src-os/mtime_clock_stubs.c +++ b/src-clock/mtime_clock_stubs.c @@ -1,8 +1,7 @@ /*--------------------------------------------------------------------------- Copyright (c) 2015 The mtime programmers. All rights reserved. Distributed under the ISC license, see license at the end of the file. - mtime release v1.3.0 - --------------------------------------------------------------------------*/ + ---------------------------------------------------------------------------*/ #include <caml/mlvalues.h> #include <caml/alloc.h> diff --git a/src-clock/runtime.js b/src-clock/runtime.js new file mode 100644 index 0000000..7a2aadc --- /dev/null +++ b/src-clock/runtime.js @@ -0,0 +1,93 @@ +/*--------------------------------------------------------------------------- + Copyright (c) 2022 The mtime programmers. All rights reserved. + Distributed under the ISC license, see license at the end of the file. + ---------------------------------------------------------------------------*/ + +//Provides: ocaml_mtime_clock_period_ns +function ocaml_mtime_clock_period_ns (_unit) { + return 0; +} + +//Provides: mtime_clock_now +//Requires: caml_int64_of_float, caml_int64_mul +//Requires: caml_raise_sys_error +function find_performance_obj () { + var test = function (o) + { return (o && o.performance && typeof o.performance.now == "function");}; + + if (test (globalThis)) { return globalThis.performance; }; + if (test (globalThis.perf_hooks)){ return globalThis.perf_hooks.performance;}; + if (typeof require == "function") { + var ph = require ("perf_hooks"); + if (test (ph)) { return ph.performance; } + } + var obj = { now: function () + { caml_raise_sys_error ("performance.now () is not available");}} + return obj; +} +var performance_obj = find_performance_obj (); +function mtime_clock_now () { + /* Conversion of DOMHighResTimeStamp to uint64 nanosecond timestamps. + + The spec https://www.w3.org/TR/hr-time-3 says DOMHighResTimeStamp + are double milliseconds that *should* be accurate to 5 microseconds. + We simply assume we have microsecond precision and multiply the + stamps given by performance.now () by 1e3 to get double microseconds. + + We then use Int64.of_float on these double microseconds to get an + uint64 in microseconds. This works in practice for the following + reasons. Let us assume we have the largest integer microsecond + timestamp representable exactly in double, i.e. 2^53 : + + 1) Assuming the zero of performance.now is when the tab is created, + our 2^53 timestamp only occurs after: + + 2^53 / 1_000_000 / (24 * 3600 * 365.25) ≅ 285.4 Julian years + + 2) 2^53 < Int64.max_int = 2^63 - 1, so seing the result of + Int64.of_float as unsigned for this timestamp is correct and in + the defined domain of the conversion function (the truncated float + must lie in [Int64.min_int;Int64.max_int] for defined behaviour). + + So the Int64.of_float conversion is unlikely to be problematic and + we simply bring the resulting uint64 microsecond to an uint64 + nanosecond by multiplying by 1000L, which for 2^53 microseconds + remains smaller than Int64.max_int, yielding a correct uint64 + nanosecond timestamp for a reasonable time range. */ + + var now_us = performance_obj.now () * 1e3; + var now_ns = caml_int64_mul (caml_int64_of_float (now_us), + caml_int64_of_float (1000)); + return now_ns; +} + +//Provides: ocaml_mtime_clock_now_ns +//Requires: mtime_clock_now +function ocaml_mtime_clock_now_ns (_unit) { + return mtime_clock_now (); +} + +//Provides: ocaml_mtime_clock_elapsed_ns +//Requires: caml_int64_sub, mtime_clock_now +var mtime_clock_start; +function ocaml_mtime_clock_elapsed_ns (_unix) { + if (!mtime_clock_start) mtime_clock_start = mtime_clock_now (); + var now = mtime_clock_now (); + return caml_int64_sub (now, mtime_clock_start); +} + +/*--------------------------------------------------------------------------- + Copyright (c) 2022 The mtime programmers + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + ---------------------------------------------------------------------------*/ diff --git a/src-jsoo/mtime_clock.ml b/src-jsoo/mtime_clock.ml deleted file mode 100644 index 9604059..0000000 --- a/src-jsoo/mtime_clock.ml +++ /dev/null @@ -1,98 +0,0 @@ -(*--------------------------------------------------------------------------- - Copyright (c) 2017 The mtime programmers. All rights reserved. - Distributed under the ISC license, see terms at the end of the file. - ---------------------------------------------------------------------------*) - -open Js_of_ocaml - -let us_to_ns = 1000L (* microsecond to nanosecond uint64 multiplier *) - -(* Get a handle on JavaScript's performance.now *) - -let performance_now_ms_unavailable () = - raise (Sys_error ("performance.now () is not available")) - -let performance_now_ms = - let has_perf = Js.Unsafe.get Dom_html.window "performance" in - match Js.Optdef.to_option has_perf with - | None -> - let typeof_require = Js.typeof (Js.Unsafe.pure_js_expr "require") in - if Js.to_string typeof_require = "function" then - let require = Js.Unsafe.pure_js_expr "require" in - let args = [| Js.Unsafe.inject (Js.string "perf_hooks") |] in - let perf_hooks = Js.Unsafe.fun_call require args in - let performance = Js.Unsafe.get perf_hooks "performance" in - fun () -> Js.Unsafe.meth_call performance "now" [||] - else - performance_now_ms_unavailable - | Some p -> - if Js.Optdef.test (Js.Unsafe.get p "now") then - fun () -> Js.Unsafe.meth_call p "now" [||] - else - performance_now_ms_unavailable - -(* Conversion of DOMHighResTimeStamp to uint64 nanosecond timestamps. - - The spec https://www.w3.org/TR/hr-time-3 says DOMHighResTimeStamp - are double milliseconds that *should* be accurate to 5 microseconds. - We simply assume we have microsecond precision and multiply the - stamps given by performance.now () by 1e3 to get double microseconds. - - We then use Int64.of_float on these double microseconds to get an - uint64 in microseconds. This works in practice for the following - reasons. Let us assume we have the largest integer microsecond - timestamp representable exactly in double, i.e. 2^53 : - - 1) Assuming the zero of performance.now is when the tab is created, - our 2^53 timestamp only occurs after: - - 2^53 / 1_000_000 / (24 * 3600 * 365.25) ≅ 285.4 Julian years - - 2) 2^53 < Int64.max_int = 2^63 - 1, so seing the result of - Int64.of_float as unsigned for this timestamp is correct and in - the defined domain of the conversion function (the truncated float - must lie in [Int64.min_int;Int64.max_int] for defined behaviour). - - So the Int64.of_float conversion is unlikely to be problematic and - we simply bring the resulting uint64 microsecond to an uint64 - nanosecond by multiplying by 1000L, which for 2^53 microseconds - remains smaller than Int64.max_int, yielding a correct uint64 - nanosecond timestamp for a reasonable time range. *) - -(* Raw interface *) - -let now_us () = performance_now_ms () *. 1e3 - -let start_us = now_us () -let elapsed_ns () = Int64.(mul (of_float @@ now_us () -. start_us) us_to_ns) -let now_ns () = Int64.(mul (of_float @@ now_us ()) us_to_ns) -let period_ns () = None - -(* Monotonic clock *) - -let elapsed () = Mtime.Span.of_uint64_ns (elapsed_ns ()) -let now () = Mtime.of_uint64_ns (now_ns ()) -let period () = Mtime.Span.unsafe_of_uint64_ns_option (period_ns ()) - -(* Counters *) - -type counter = float -let counter = now_us -let count c = - Mtime.Span.of_uint64_ns (Int64.(mul (of_float @@ now_us () -. c)) us_to_ns) - -(*--------------------------------------------------------------------------- - Copyright (c) 2017 The mtime programmers - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - ---------------------------------------------------------------------------*) diff --git a/src-jsoo/mtime_clock.mli b/src-jsoo/mtime_clock.mli deleted file mode 100644 index 72c78f2..0000000 --- a/src-jsoo/mtime_clock.mli +++ /dev/null @@ -1,125 +0,0 @@ -(*--------------------------------------------------------------------------- - Copyright (c) 2017 The mtime programmers. All rights reserved. - Distributed under the ISC license, see terms at the end of the file. - ---------------------------------------------------------------------------*) - -(** Monotonic time clock. - - [Mtime_clock] provides access to a system monotonic clock. This - time increases monotonically and is not subject to operating - system calendar time adjustments. - - Only use {!Mtime_clock.now} if you need inter-process time - correlation, otherwise prefer {!Mtime_clock.elapsed} and - {{!Mtime_clock.counters}counters}. - - Consult important information about {{!err}error handling} - and {{!platform_support}platform support}. - - Concrete implementation of this interfaces are provided by the - [mtime.clock.os] and [mtime.clock.jsoo] packages against which you - should compile depending on your target. *) - -(** {1:clock Monotonic clock} *) - -val elapsed : unit -> Mtime.span -(** [elapsed ()] is the monotonic time span elapsed since the - beginning of the program. - - @raise Sys_error see {{!err}error handling} *) - -val now : unit -> Mtime.t -(** [now ()] is the current system-relative monotonic timestamp. Its - absolute value is meaningless. - - @raise Sys_error see {{!err}error handling} *) - -val period : unit -> Mtime.span option -(** [period ()] is the clock's period as a monotonic time span (if - available). *) - -(** {1:counters Time counters} *) - -type counter -(** The type for monotonic wall-clock time counters. *) - -val counter : unit -> counter -(** [counter ()] is a counter counting from now on. - - @raise Sys_error see {{!err}error handling} *) - -val count : counter -> Mtime.span -(** [count c] is the monotonic time span elapsed since [c] was created. *) - -(** {1:raw Monotonic clock raw interface} *) - -val elapsed_ns : unit -> int64 -(** [elapsed_ns ()] is the {e unsigned} 64-bit integer nanosecond monotonic - time span elapsed since the beginning of the program. - - @raise Sys_error see {{!err}error handling} *) - -val now_ns : unit -> int64 -(** [now_ns ()] is an {e unsigned} 64-bit integer nanosecond - system-relative monotonic timestamp. The absolute value is - meaningless. - - @raise Sys_error see {{!err}error handling} *) - -val period_ns : unit -> int64 option -(** [period_ns ()] is the clock's period as an {e unsigned} 64-bit - integer nanosecond monotonic time span (if available). *) - -(** {1:err Error handling} - - The functions {!elapsed}, {!now}, {!val-counter}, {!elapsed_ns} and - {!now_ns} raise [Sys_error] whenever they can't determine the - current time or that it doesn't fit in [Mtime]'s range. Usually - this exception should only be catched at the toplevel of your - program to log it and abort the program. It indicates a serious - error condition in the system. - - All the other functions, whose functionality is less essential, - simply silently return [None] if they can't determine the - information either because it is unavailable or because an error - occured. - - {1:platform_support Platform support} - - {ul - {- Platforms with a POSIX clock (includes Linux) use - {{:http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html}[clock_gettime]} - with CLOCK_MONOTONIC.} - {- Darwin uses - {{:https://developer.apple.com/library/mac/qa/qa1398/_index.html}[mach_absolute_time]}.} - {- Windows uses - {{:https://msdn.microsoft.com/en-us/library/windows/desktop/aa373083%28v=vs.85%29.aspx}Performance counters}. } - {- JavaScript uses - {{:http://www.w3.org/TR/hr-time/}[performance.now]} (consult - {{:http://caniuse.com/#feat=high-resolution-time}availability}) - which returns a - {{:http://www.w3.org/TR/hr-time/#sec-DOMHighResTimeStamp}double - floating point value} in milliseconds with - resolution up to the microsecond.} - {- JavaScript running on Node.js uses the built-in - {{:https://nodejs.org/api/perf_hooks.html#perf_hooks_performance_now}[perf_hooks]} - module, which provides an interface compatible to the [performance] - module in browsers.}} -*) - - -(*--------------------------------------------------------------------------- - Copyright (c) 2017 The mtime programmers - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - ---------------------------------------------------------------------------*) diff --git a/src-jsoo/mtime_clock.mllib b/src-jsoo/mtime_clock.mllib deleted file mode 100644 index 11e2547..0000000 --- a/src-jsoo/mtime_clock.mllib +++ /dev/null @@ -1 +0,0 @@ -Mtime_clock
\ No newline at end of file diff --git a/src/mtime.ml b/src/mtime.ml index dd34b53..f793d8f 100644 --- a/src/mtime.ml +++ b/src/mtime.ml @@ -21,10 +21,6 @@ let s_to_hour = 1. /. hour_to_s let s_to_day = 1. /. day_to_s let s_to_year = 1. /. year_to_s -(* Unsigned comparison *) - -let uint64_compare a b = Int64.(compare (sub a min_int) (sub b min_int)) - (* Time spans Time spans are in nanoseconds and we represent them by an unsigned @@ -35,31 +31,40 @@ type span = int64 (* unsigned nanoseconds *) module Span = struct type t = span - - let to_uint64_ns s = s - let of_uint64_ns ns = ns - - let unsafe_of_uint64_ns_option nsopt = nsopt - - (* Predicates *) - - let equal = Int64.equal - let compare = uint64_compare - - (* Constants *) - let zero = 0L let one = 1L let min_span = zero let max_span = -1L + (* Predicates *) + + let equal = Int64.equal + let compare = Int64.unsigned_compare + (* Arithmetic *) let add = Int64.add let abs_diff s0 s1 = if compare s0 s1 < 0 then Int64.sub s1 s0 else Int64.sub s0 s1 - (* Converting time spans *) + (* Durations *) + + let ( * ) n s = Int64.mul (Int64.of_int n) s + let ns = 1L + let us = 1_000L + let ms = 1_000_000L + let s = 1_000_000_000L + let min = 60_000_000_000L + let hour = 3600_000_000_000L + let day = 86400_000_000_000L + let year = 31_557_600_000_000_000L + + (* Converting *) + + let to_uint64_ns s = s + let of_uint64_ns ns = ns + + let unsafe_of_uint64_ns_option nsopt = nsopt let to_ns s = (Int64.to_float s) let to_us s = (Int64.to_float s) *. 1e-3 @@ -78,7 +83,10 @@ module Span = struct let ns_to_year = ns_to_s *. s_to_year let to_year s = (Int64.to_float s) *. ns_to_year - (* Pretty printing *) + (* Formatting + + Maybe one day we could replace this by B00_std.Fmt.uint64_ns_span + which does all the arithmetic on uint64. *) let round x = floor (x +. 0.5) let round_dfrac d x = (* rounds [x] to the [d]th decimal digit *) @@ -143,11 +151,13 @@ type t = int64 let to_uint64_ns s = s let of_uint64_ns ns = ns +let min_stamp = 0L +let max_stamp = -1L (* Predicates *) let equal = Int64.equal -let compare = uint64_compare +let compare = Int64.unsigned_compare let is_earlier t ~than = compare t than < 0 let is_later t ~than = compare t than > 0 @@ -162,7 +172,7 @@ let add_span t s = let sub_span t s = if compare t s < 0 then None else Some (Int64.sub t s) -(* Pretty printing *) +(* Formatters *) let pp ppf ns = Format.fprintf ppf "%Luns" ns let dump ppf ns = Format.fprintf ppf "%Lu" ns diff --git a/src/mtime.mli b/src/mtime.mli index 9398065..6d8d9ca 100644 --- a/src/mtime.mli +++ b/src/mtime.mli @@ -33,17 +33,7 @@ module Span : sig (** {1:spans Monotonic time spans} *) type t = span - (** See {!type:span}. *) - - val to_uint64_ns : span -> int64 - (** [to_uint64_ns span] is [span] as an {e unsigned} 64-bit integer - nanosecond span. *) - - val of_uint64_ns : int64 -> span - (** [of_uint64_ns d] is the {e unsigned} 64-bit integer nanosecond - span as a span. *) - - (** {1 Constants} *) + (** See {!Mtime.type-span}. *) val zero : span (** [zero] is a span of 0ns. *) @@ -55,9 +45,9 @@ module Span : sig (** [min_span] is {!zero}. *) val max_span : span - (** [max_span] is 2^64-1ns. *) + (** [max_span] is 2{^64}-1ns. *) - (** {1 Predicates} *) + (** {1:preds Predicates} *) val equal : span -> span -> bool (** [equal span span'] is [true] iff [span] and [span'] are equal. *) @@ -76,9 +66,47 @@ module Span : sig (** [abs_diff span span'] is the absolute difference between [span] and [span']. *) - (** {1 Converting time spans} + (** {1:const Durations} *) + + val ( * ) : int -> span -> span + (** [n * dur] is [n] times duration [dur]. + + {b Warning.} Does not check for overflow or that [n] is + positive. *) + + val ns : span + (** [ns] is a nanosecond duration, 1·10{^-9}s. *) + + val us : span + (** [us] is a microsecond duration, 1·10{^-6}s. *) + + val ms : span + (** [ms] is a millisecond duration, 1·10{^-3}s. *) + + val s : span + (** [s] is a second duration, 1s. *) - See {{!convert}this section} for time scale definitions. *) + val min : span + (** [min] is a minute duration, 60s. *) + + val hour : span + (** [hour] is an hour duration, 3600s. *) + + val day : span + (** [day] is a day duration, 86'400s. *) + + val year : span + (** [year] is a Julian year duration (365.25 days), 31'557'600s. *) + + (** {1:convert Converting} *) + + val to_uint64_ns : span -> int64 + (** [to_uint64_ns span] is [span] as an {e unsigned} 64-bit integer + nanosecond span. *) + + val of_uint64_ns : int64 -> span + (** [of_uint64_ns u] is the {e unsigned} 64-bit integer nanosecond + span [u] as a span. *) val to_ns : span -> float (** [to_ns span] is [span] in nanoseconds (1e-9s). *) @@ -104,20 +132,20 @@ module Span : sig val to_year : span -> float (** [to_year span] is [span] in Julian years (365.25 days, 31'557'600s). *) - (** {1 Pretty printing} *) + (** {1:fmt Formatters} *) val pp : Format.formatter -> span -> unit - (** [pp_span ppf span] prints an unspecified representation of + (** [pp_span ppf span] formats an unspecified representation of [span] on [ppf]. The representation is not fixed-width, depends on the magnitude of [span] and uses locale independent {{!convert}standard time scale} abbreviations. *) val pp_float_s : Format.formatter -> float -> unit - (** [pp_float_s] prints like {!pp} does but on a floating + (** [pp_float_s] formats like {!pp} does but on a floating point seconds time span value (which can be negative). *) val dump : Format.formatter -> t -> unit - (** [dump ppf span] prints an unspecified raw representation of [span] + (** [dump ppf span] formats an unspecified raw representation of [span] on [ppf]. *) (**/**) @@ -148,7 +176,13 @@ val of_uint64_ns : int64 -> t used with other timestamp values that are know to come from the same operating system run. *) -(** {1:preds Predicates} *) +val min_stamp : t +(** [min_stamp] is the earliest timestamp. *) + +val max_stamp : t +(** [max_stamp] is the latest timestamp. *) + +(** {2:preds Predicates} *) val equal : t -> t -> bool (** [equal t t'] is [true] iff [t] and [t'] are equal. *) @@ -162,7 +196,7 @@ val is_earlier : t -> than:t -> bool val is_later : t -> than:t -> bool (** [is_later t ~than] is [true] iff [t] occurred after [than]. *) -(** {1:arith Arithmetic} *) +(** {2:arith Arithmetic} *) val span : t -> t -> span (** [span t t'] is the span between [t] and [t'] regardless of the @@ -174,18 +208,20 @@ val add_span : t -> span -> t option val sub_span : t -> span -> t option (** [sub_span t s] is the timestamp [s] units earlier than [t] or - [None] if overflows. *) + [None] if the result underflows. *) -(** {1:pretty Pretty printing} *) +(** {2:fmt Formatting} *) val pp : Format.formatter -> t -> unit -(** [pp ppf t] prints [t] as an {e unsigned} 64-bit integer nanosecond - timestamp. Note that the absolute value is meaningless. *) +(** [pp ppf t] formats [t] as an {e unsigned} 64-bit integer + nanosecond timestamp. Note that the absolute value is + meaningless. *) val dump : Format.formatter -> t -> unit -(** [dump ppf t] prints an unspecified raw representation of [t] on [ppf]. *) +(** [dump ppf t] formats an unspecified raw representation of [t] on + [ppf]. *) -(** {1:convert Time scale conversion} +(** {1:timescale Time scale conversion (deprecated)} The following convenience constants relate time scales to seconds. Used as multiplicands they can be used to convert these units @@ -200,50 +236,78 @@ val dump : Format.formatter -> t -> unit by the International Astronomical Union (IAU). *) val ns_to_s : float -(** [ns_to_s] is [1e-9] the number of seconds in one nanosecond. *) +[@@ocaml.deprecated "Use 1e-9 instead."] +(** [ns_to_s] is [1e-9] the number of seconds in one nanosecond. + @deprecated *) val us_to_s : float -(** [us_to_s] is [1e-6], the number of seconds in one microsecond. *) +[@@ocaml.deprecated "Use 1e-6 instead."] +(** [us_to_s] is [1e-6], the number of seconds in one microsecond. + @deprecated *) val ms_to_s : float -(** [ms_to_s] is [1e-3], the number of seconds in one millisecond. *) +[@@ocaml.deprecated "Use 1e-3 instead."] +(** [ms_to_s] is [1e-3], the number of seconds in one millisecond. + @deprecated *) val min_to_s : float -(** [min_to_s] is [60.], the number of seconds in one SI-accepted minute. *) +[@@ocaml.deprecated "Use 60. instead."] +(** [min_to_s] is [60.], the number of seconds in one SI-accepted minute. + @deprecated *) val hour_to_s : float -(** [hour_to_s] is [3600.], the number of seconds in one SI-accepted hour. *) +[@@ocaml.deprecated "Use 3600. instead."] +(** [hour_to_s] is [3600.], the number of seconds in one SI-accepted hour. + @deprecated *) val day_to_s : float -(** [day_to_s] is [86_400.], the number of seconds in one SI-accepted day. *) +[@@ocaml.deprecated "Use 86_400. instead."] +(** [day_to_s] is [86_400.], the number of seconds in one SI-accepted day. + @deprecated *) val year_to_s : float -(** [year_to_s] is [31_557_600.], the number of seconds in a Julian year. *) +[@@ocaml.deprecated "Use 31_557_600. instead."] +(** [year_to_s] is [31_557_600.], the number of seconds in a Julian year. + @deprecated *) val s_to_ns : float -(** [s_to_ns] is [1e9] the number of nanoseconds in one second. *) +[@@ocaml.deprecated "Use 1e9 instead."] +(** [s_to_ns] is [1e9] the number of nanoseconds in one second. + @deprecated *) val s_to_us : float -(** [s_to_us] is [1e6], the number of microseconds in one second. *) +[@@ocaml.deprecated "Use 1e6 instead."] +(** [s_to_us] is [1e6], the number of microseconds in one second. + @deprecated *) val s_to_ms : float -(** [s_to_ms] is [1e3], the number of milliseconds in one second. *) +[@@ocaml.deprecated "Use 1e3 instead."] +(** [s_to_ms] is [1e3], the number of milliseconds in one second. + @deprecated *) val s_to_min : float +[@@ocaml.deprecated "Use (1. /. 60.) instead."] (** [s_to_min] is [1. /. 60.], the number of SI-accepted minutes in - one second. *) + one second. + @deprecated *) val s_to_hour : float +[@@ocaml.deprecated "Use (1. /. 3600.) instead."] (** [s_to_hour] is [1. /. 3600.], the number of SI-accepted hours in - one second. *) + one second. + @deprecated *) val s_to_day : float +[@@ocaml.deprecated "Use (1. /. 86400.) instead."] (** [s_to_day] is [1. /. 86400.], the number of SI-accepted days in - one second. *) + one second. + @deprecated *) val s_to_year : float +[@@ocaml.deprecated "Use (1. /. 31_557_600.) instead."] (** [s_to_year] is [1. /. 31_557_600.], the number of Julian years - in one second. *) + in one second. + @deprecated *) (*--------------------------------------------------------------------------- Copyright (c) 2015 The mtime programmers diff --git a/src/mtime_clock.mli b/src/mtime_clock.mli index 72c78f2..d35b9a0 100644 --- a/src/mtime_clock.mli +++ b/src/mtime_clock.mli @@ -14,11 +14,7 @@ {{!Mtime_clock.counters}counters}. Consult important information about {{!err}error handling} - and {{!platform_support}platform support}. - - Concrete implementation of this interfaces are provided by the - [mtime.clock.os] and [mtime.clock.jsoo] packages against which you - should compile depending on your target. *) + and {{!platform_support}platform support}. *) (** {1:clock Monotonic clock} *) @@ -26,13 +22,13 @@ val elapsed : unit -> Mtime.span (** [elapsed ()] is the monotonic time span elapsed since the beginning of the program. - @raise Sys_error see {{!err}error handling} *) + Raises {!Sys_error}, see {{!err}error handling} *) val now : unit -> Mtime.t (** [now ()] is the current system-relative monotonic timestamp. Its absolute value is meaningless. - @raise Sys_error see {{!err}error handling} *) + Raises {!Sys_error}, see {{!err}error handling} *) val period : unit -> Mtime.span option (** [period ()] is the clock's period as a monotonic time span (if @@ -46,7 +42,7 @@ type counter val counter : unit -> counter (** [counter ()] is a counter counting from now on. - @raise Sys_error see {{!err}error handling} *) + Raises {!Sys_error}, see {{!err}error handling} *) val count : counter -> Mtime.span (** [count c] is the monotonic time span elapsed since [c] was created. *) @@ -57,14 +53,14 @@ val elapsed_ns : unit -> int64 (** [elapsed_ns ()] is the {e unsigned} 64-bit integer nanosecond monotonic time span elapsed since the beginning of the program. - @raise Sys_error see {{!err}error handling} *) + Raises {!Sys_error}, see {{!err}error handling} *) val now_ns : unit -> int64 (** [now_ns ()] is an {e unsigned} 64-bit integer nanosecond system-relative monotonic timestamp. The absolute value is meaningless. - @raise Sys_error see {{!err}error handling} *) + Raises {!Sys_error}, see {{!err}error handling} *) val period_ns : unit -> int64 option (** [period_ns ()] is the clock's period as an {e unsigned} 64-bit diff --git a/src/mtime_top_init.ml b/src/mtime_top_init.ml index c9a3aed..c6a7382 100644 --- a/src/mtime_top_init.ml +++ b/src/mtime_top_init.ml @@ -3,8 +3,8 @@ Distributed under the ISC license, see terms at the end of the file. ---------------------------------------------------------------------------*) -#install_printer Mtime.pp -#install_printer Mtime.Span.pp +#install_printer Mtime.pp;; +#install_printer Mtime.Span.pp;; (*--------------------------------------------------------------------------- Copyright (c) 2015 The mtime programmers diff --git a/test-jsoo/test_jsoo.html b/test-jsoo/test_jsoo.html deleted file mode 100644 index e60a777..0000000 --- a/test-jsoo/test_jsoo.html +++ /dev/null @@ -1,48 +0,0 @@ -<!DOCTYPE html> -<!-- - Copyright (c) 2014 The mtime programmers. All rights reserved. - Distributed under the ISC license, see license at the end of the file. - mtime release v1.3.0 ---> -<html lang="en"> -<head> - <meta charset="utf-8"> - <meta name="viewport" content="width=device-width, - initial-scale=1.0"> - <script type="text/javascript" defer="defer" src="test_jsoo.js"></script> - <style type="text/css"> - h1 { font-size: 2.5rem; font-weight: 300; text-transform: uppercase; } - body { background-color: black; - color: #A0A0A0; - font-size: 1rem; - line-height: 1.3125rem; - font-family: monospace; - font-weight: 300; - margin: 4em; } - - div { font-size: 0.8rem; margin-top:1.3125rem; } - p { margin:0rem; padding:0rem; white-space: pre; } - </style> - <title>Mtime tests</title> -</head> -<body> - <noscript>Sorry, you need to enable JavaScript to see this page.</noscript> - <h1>Mtime tests</h1> -</body> -</html> - -<!-- - Copyright (c) 2015 The mtime programmers - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - --> diff --git a/test-jsoo/test_jsoo.ml b/test-jsoo/test_jsoo.ml deleted file mode 100644 index 970d7b2..0000000 --- a/test-jsoo/test_jsoo.ml +++ /dev/null @@ -1,42 +0,0 @@ -(*--------------------------------------------------------------------------- - Copyright (c) 2014 The mtime programmers. All rights reserved. - Distributed under the ISC license, see terms at the end of the file. - ---------------------------------------------------------------------------*) - -open Js_of_ocaml - -let setup_log () = - let log = Dom_html.(createDiv document) in - let add_entry s = - let e = Dom_html.(createP document) in - Js.Unsafe.set e "innerHTML" (Js.string s); - Dom.appendChild log e; - in - Dom.appendChild (Js.Unsafe.get Dom_html.document "body") log; - Sys_js.set_channel_flusher stdout add_entry; - Sys_js.set_channel_flusher stderr add_entry; - () - -let main _ = - setup_log (); - ignore (Tests.run ()); - Js._false - -let () = Js.Unsafe.set Dom_html.window "onload" (Dom_html.handler main) - - -(*--------------------------------------------------------------------------- - Copyright (c) 2014 The mtime programmers - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - ---------------------------------------------------------------------------*) diff --git a/test-jsoo/test_node.ml b/test-jsoo/test_node.ml deleted file mode 100644 index 731bc35..0000000 --- a/test-jsoo/test_node.ml +++ /dev/null @@ -1,22 +0,0 @@ -(*--------------------------------------------------------------------------- - Copyright (c) 2015 The mtime programmers. All rights reserved. - Distributed under the ISC license, see terms at the end of the file. - ---------------------------------------------------------------------------*) - -let () = Tests.run () - -(*--------------------------------------------------------------------------- - Copyright (c) 2015 The mtime programmers - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - ---------------------------------------------------------------------------*) diff --git a/test-jsoo/tests.ml b/test-jsoo/tests.ml deleted file mode 100644 index 79e2e18..0000000 --- a/test-jsoo/tests.ml +++ /dev/null @@ -1,275 +0,0 @@ -(*--------------------------------------------------------------------------- - Copyright (c) 2015 The mtime programmers. All rights reserved. - Distributed under the ISC license, see terms at the end of the file. - ---------------------------------------------------------------------------*) - -let log f = Format.printf (f ^^ "@.") - -let test_available () = - try ignore (Mtime_clock.elapsed ()) with - | Sys_error e -> log "[ERROR] no monotonic time available: %s" e; exit 1 - -let count = ref 0 -let fail = ref 0 -let test f v = - incr count; - try f v with - | Failure _ | Assert_failure _ as exn -> - let bt = Printexc.get_backtrace () in - incr fail; log "[ERROR] %s@.%s" (Printexc.to_string exn) bt - -let log_result () = - if !fail = 0 then log "[OK] All %d tests passed !" !count else - log "[FAIL] %d failure(s) out of %d" !fail !count; - () - -let test_secs_in () = - log "Testing Mtime.{s_to_*,*_to_s}"; - let equalf f f' = abs_float (f -. f') < 1e-9 in - assert (Mtime.ns_to_s = 1e-9); - assert (Mtime.us_to_s = 1e-6); - assert (Mtime.ms_to_s = 1e-3); - assert (Mtime.min_to_s = 60.); - assert (Mtime.hour_to_s = (60. *. 60.)); - assert (Mtime.day_to_s = (24. *. 60. *. 60.)); - assert (Mtime.year_to_s = (365.25 *. 24. *. 60. *. 60.)); - assert (equalf (Mtime.s_to_ns *. 1e-9) 1.); - assert (equalf (Mtime.s_to_us *. 1e-6) 1.); - assert (equalf (Mtime.s_to_ms *. 1e-3) 1.); - assert (equalf (Mtime.s_to_min *. 60.) 1.); - assert (equalf (Mtime.s_to_hour *. (60. *. 60.)) 1.); - assert (equalf (Mtime.s_to_day *. (24. *. 60. *. 60.)) 1.); - assert (equalf (Mtime.s_to_year *. (365.25 *. 24. *. 60. *. 60.)) 1.); - () - -let test_pp_span_s () = - (* N.B. this test may fail as it may be sensitive to black art of - floating point formatting. Also note that ties on negative - numbers round towards positive infinity, i.e. -0.5 rounds to 0. *) - log "Testing Mtime.pp_span_s"; - let pp s = Format.asprintf "%a" Mtime.Span.pp_float_s s in - let eq_str s s' = if s <> s' then failwith (Printf.sprintf "%S <> %S" s s') in - (* sub ns scale *) - eq_str (pp 1.0e-10) "0us"; - eq_str (pp ~-.1.0e-10) "0us"; - eq_str (pp 4.0e-10) "0us"; - eq_str (pp ~-.4.0e-10) "0us"; - eq_str (pp 6.0e-10) "0.001us"; - eq_str (pp ~-.6.0e-10) "-0.001us"; - eq_str (pp 9.0e-10) "0.001us"; - eq_str (pp ~-.9.0e-10) "-0.001us"; - (* ns scale *) - eq_str (pp 2.0e-9) "0.002us"; - eq_str (pp ~-.2.0e-9) "-0.002us"; - eq_str (pp 2.136767676e-9) "0.002us"; - eq_str (pp ~-.2.136767676e-9) "-0.002us"; - eq_str (pp 2.6e-9) "0.003us"; - eq_str (pp ~-.2.6e-9) "-0.003us"; - eq_str (pp 2.836767676e-9) "0.003us"; - eq_str (pp ~-.2.836767676e-9) "-0.003us"; - (* us scale *) - eq_str (pp 2.0e-6) "2us"; - eq_str (pp ~-.2.0e-6) "-2us"; - eq_str (pp 2.555e-6) "2.555us"; - eq_str (pp ~-.2.555e-6) "-2.555us"; - eq_str (pp 2.5556e-6) "2.556us"; - eq_str (pp ~-.2.5556e-6) "-2.556us"; - eq_str (pp 99.9994e-6) "99.999us"; - eq_str (pp ~-.99.9994e-6) "-99.999us"; - eq_str (pp 99.9996e-6) "100us"; - eq_str (pp ~-.99.9996e-6) "-100us"; - eq_str (pp 100.1555e-6) "100us"; - eq_str (pp ~-.100.1555e-6) "-100us"; - eq_str (pp 100.5555e-6) "101us"; - eq_str (pp ~-.100.5555e-6) "-101us"; - eq_str (pp 100.6555e-6) "101us"; - eq_str (pp ~-.100.6555e-6) "-101us"; - eq_str (pp 999.4e-6) "999us"; - eq_str (pp ~-.999.4e-6) "-999us"; - eq_str (pp 999.6e-6) "1ms"; - eq_str (pp ~-.999.6e-6) "-1ms"; - (* ms scale *) - eq_str (pp 1e-3) "1ms"; - eq_str (pp ~-.1e-3) "-1ms"; - eq_str (pp 1.555e-3) "1.555ms"; - eq_str (pp ~-.1.555e-3) "-1.555ms"; - eq_str (pp 1.5556e-3) "1.556ms"; - eq_str (pp ~-.1.5556e-3) "-1.556ms"; - eq_str (pp 99.9994e-3) "99.999ms"; - eq_str (pp ~-.99.9994e-3) "-99.999ms"; - eq_str (pp 99.9996e-3) "100ms"; - eq_str (pp ~-.99.9996e-3) "-100ms"; - eq_str (pp 100.1555e-3) "100ms"; - eq_str (pp ~-.100.1555e-3) "-100ms"; - eq_str (pp 100.5555e-3) "101ms"; - eq_str (pp ~-.100.5555e-3) "-101ms"; - eq_str (pp 100.6555e-3) "101ms"; - eq_str (pp ~-.100.6555e-3) "-101ms"; - eq_str (pp 999.4e-3) "999ms"; - eq_str (pp ~-.999.4e-3) "-999ms"; - eq_str (pp 999.6e-3) "1s"; - eq_str (pp ~-.999.6e-3) "-1s"; - (* s scale *) - eq_str (pp 1.) "1s"; - eq_str (pp ~-.1.) "-1s"; - eq_str (pp 1.555) "1.555s"; - eq_str (pp ~-.1.555) "-1.555s"; - eq_str (pp 1.5554) "1.555s"; - eq_str (pp ~-.1.5554) "-1.555s"; - eq_str (pp 1.5556) "1.556s"; - eq_str (pp ~-.1.5556) "-1.556s"; - eq_str (pp 59.) "59s"; - eq_str (pp ~-.59.) "-59s"; - eq_str (pp 59.9994) "59.999s"; - eq_str (pp ~-.59.9994) "-59.999s"; - eq_str (pp 59.9996) "1min"; - eq_str (pp ~-.59.9996) "-1min"; - (* min scale *) - eq_str (pp 60.) "1min"; - eq_str (pp ~-.60.) "-1min"; - eq_str (pp 62.) "1min2s"; - eq_str (pp ~-.62.) "-1min2s"; - eq_str (pp 62.4) "1min2s"; - eq_str (pp ~-.62.4) "-1min2s"; - eq_str (pp 3599.) "59min59s"; - eq_str (pp ~-.3599.) "-59min59s"; - (* hour scale *) - eq_str (pp 3600.0) "1h"; - eq_str (pp ~-.3600.0) "-1h"; - eq_str (pp 3629.0) "1h"; - eq_str (pp ~-.3629.0) "-1h"; - eq_str (pp 3660.0) "1h1min"; - eq_str (pp ~-.3660.0) "-1h1min"; - eq_str (pp 7164.0) "1h59min"; - eq_str (pp ~-.7164.0) "-1h59min"; - eq_str (pp 7200.0) "2h"; - eq_str (pp ~-.7200.0) "-2h"; - eq_str (pp 86399.) "23h59min"; - eq_str (pp ~-.86399.) "-23h59min"; - (* day scale *) - eq_str (pp 86400.) "1d"; - eq_str (pp ~-.86400.) "-1d"; - eq_str (pp (86400. +. (23. *. 3600.))) "1d23h"; - eq_str (pp ~-.(86400. +. (23. *. 3600.))) "-1d23h"; - eq_str (pp (86400. +. (24. *. 3600.))) "2d"; - eq_str (pp ~-.(86400. +. (24. *. 3600.))) "-2d"; - eq_str (pp (365.25 *. 86_400. -. 1.)) "365d5h"; - eq_str (pp ~-.(365.25 *. 86_400. -. 1.)) "-365d5h"; - (* year scale *) - eq_str (pp (31557600.)) "1a"; - eq_str (pp ~-.(365.25 *. 86_400.)) "-1a"; - eq_str (pp (365.25 *. 86_400. +. 86400.)) "1a1d"; - eq_str (pp ~-.(365.25 *. 86_400. +. 86400.)) "-1a1d"; - eq_str (pp (365.25 *. 2. *. 86_400.)) "2a"; - eq_str (pp ~-.(365.25 *. 2. *. 86_400.)) "-2a"; - eq_str (pp (365.25 *. 2. *. 86_400. -. 1.)) "1a365d"; - eq_str (pp ~-.(365.25 *. 2. *. 86_400. -. 1.)) "-1a365d"; - () - -let test_counters () = - log "Test counters"; - let count max = - let c = Mtime_clock.counter () in - for i = 1 to max do () done; - Mtime_clock.count c - in - let do_count max = - let span = count max in - let span_ns = Mtime.Span.to_uint64_ns span in - let span_s = Mtime.Span.to_s span in - log " * Count to % 8d: % 10Luns %.10fs %a" - max span_ns span_s Mtime.Span.pp span - in - do_count 1000000; - do_count 100000; - do_count 10000; - do_count 1000; - do_count 100; - do_count 10; - do_count 1; - () - -let test_elapsed () = - log "Test Mtime_clock.elapsed ns - s - pp - dump"; - let span = Mtime_clock.elapsed () in - log " * Elapsed: %Luns - %gs - %a - %a" - (Mtime.Span.to_uint64_ns span) (Mtime.Span.to_s span) - Mtime.Span.pp span Mtime.Span.dump span; - () - -let test_now () = - log "Test Mtime_clock.now ns - s - pp - dump "; - let t = Mtime_clock.now () in - let span = Mtime.(span t (of_uint64_ns 0_L)) in - log " * System: %Luns - %gs - %a - %a" - (Mtime.to_uint64_ns t) (Mtime.Span.to_s span) Mtime.pp t Mtime.dump t; - () - -let test_span_compare () = - log "Test Mtime.Span.compare"; - let zero_mtime = Mtime.Span.of_uint64_ns 0_L in - let large_mtime = Mtime.Span.of_uint64_ns Int64.max_int in - let larger_mtime = Mtime.Span.of_uint64_ns Int64.min_int in - let max_mtime = Mtime.Span.of_uint64_ns (-1_L) in - let (<) x y = Mtime.Span.compare x y < 0 in - assert (zero_mtime < large_mtime); - assert (zero_mtime < larger_mtime); - assert (zero_mtime < max_mtime); - assert (large_mtime < larger_mtime); - assert (large_mtime < max_mtime); - assert (larger_mtime < max_mtime); - let (<) x y = Mtime.Span.compare y x > 0 in - assert (zero_mtime < large_mtime); - assert (zero_mtime < large_mtime); - assert (zero_mtime < larger_mtime); - assert (zero_mtime < max_mtime); - assert (large_mtime < larger_mtime); - assert (large_mtime < max_mtime); - assert (larger_mtime < max_mtime); - () - -let test_span_constants () = - log "Test Mtime.Span.{zero,one,max_span,min_span}"; - let (<) x y = Mtime.Span.compare x y < 0 in - assert (Mtime.Span.zero < Mtime.Span.one); - assert (Mtime.Span.zero < Mtime.Span.max_span); - assert (Mtime.Span.min_span < Mtime.Span.one); - assert (Mtime.Span.min_span < Mtime.Span.max_span); - assert (Mtime.Span.one < Mtime.Span.max_span); - () - -let test_span_arith () = - log "Test Mtime.Span.{abs_diff,add}"; - assert (Mtime.Span.(equal (add zero one) one)); - assert (Mtime.Span.(equal (add one zero) one)); - assert (Mtime.Span.(equal (add (abs_diff max_span one) one) max_span)); - () - -let run () = - test test_available (); - test test_secs_in (); - test test_pp_span_s (); - test test_counters (); - test test_elapsed (); - test test_now (); - test test_span_compare (); - test test_span_constants (); - test_span_arith (); - log_result (); - exit !fail - -(*--------------------------------------------------------------------------- - Copyright (c) 2015 The mtime programmers - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - ---------------------------------------------------------------------------*) diff --git a/test-os/min_os.ml b/test-os/min_os.ml deleted file mode 100644 index 1857966..0000000 --- a/test-os/min_os.ml +++ /dev/null @@ -1,15 +0,0 @@ -(* - Compile with: - ocamlfind ocamlc \ - -package mtime,mtime.clock.os -linkpkg -o min_os.byte min_os.ml - ocamlfind ocamlopt \ - -package mtime,mtime.clock.os -linkpkg -o min_os.native min_os.ml *) - -let () = - Format.printf "Elapsed: %a@." Mtime.Span.pp (Mtime_clock.elapsed ()); - Format.printf "Timestamp: %a@." Mtime.pp (Mtime_clock.now ()); - Format.printf "Clock period: %s@." - begin match Mtime_clock.period () with - | None -> "unknown" | Some s -> Format.asprintf "%a" Mtime.Span.pp s - end; - () diff --git a/test/min_clock.ml b/test/min_clock.ml new file mode 100644 index 0000000..02c0db8 --- /dev/null +++ b/test/min_clock.ml @@ -0,0 +1,23 @@ +(* + Compile with: + + ocamlfind ocamlopt \ + -package mtime.clock.os -linkpkg -o min_clock.native min_clock.ml + + ocamlfind ocamlc \ + -package mtime.clock.os -linkpkg -o min_clock.byte min_clock.ml + + js_of_ocaml \ + $(ocamlfind query mtime.clock.os -predicates javascript -o-format) \ + min_clock.byte +*) + +let main () = + Format.printf "Elapsed: %a@." Mtime.Span.pp (Mtime_clock.elapsed ()); + Format.printf "Timestamp: %a@." Mtime.pp (Mtime_clock.now ()); + Format.printf "Clock period: %s@." + (match Mtime_clock.period () with + | None -> "unknown" | Some s -> Format.asprintf "%a" Mtime.Span.pp s); + () + +let () = if !Sys.interactive then () else main () diff --git a/test-os/test.ml b/test/test.ml index 731bc35..731bc35 100644 --- a/test-os/test.ml +++ b/test/test.ml diff --git a/test-os/tests.ml b/test/tests.ml index 79e2e18..6ea2500 100644 --- a/test-os/tests.ml +++ b/test/tests.ml @@ -23,9 +23,11 @@ let log_result () = log "[FAIL] %d failure(s) out of %d" !fail !count; () +[@@@alert "-deprecated"] let test_secs_in () = log "Testing Mtime.{s_to_*,*_to_s}"; let equalf f f' = abs_float (f -. f') < 1e-9 in + assert (Mtime.ns_to_s = 1e-9); assert (Mtime.us_to_s = 1e-6); assert (Mtime.ms_to_s = 1e-3); @@ -41,6 +43,7 @@ let test_secs_in () = assert (equalf (Mtime.s_to_day *. (24. *. 60. *. 60.)) 1.); assert (equalf (Mtime.s_to_year *. (365.25 *. 24. *. 60. *. 60.)) 1.); () +[@@@alert "+deprecated"] let test_pp_span_s () = (* N.B. this test may fail as it may be sensitive to black art of |