Created
October 22, 2017 09:43
-
-
Save eras/8540363812c95b5f7a6ab1704531146c to your computer and use it in GitHub Desktop.
Simple C call time benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
ocamlfind query bench || opam install bench | |
ocamlfind ocamlopt -linkpkg -o foo foo-c.c foo.ml -package unix,bench |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <caml/memory.h> | |
static int x = 0; | |
void foo_test(value nothing) | |
{ | |
CAMLparam0(); | |
++x; | |
CAMLreturn0; | |
} | |
value foo_info(value nothing) | |
{ | |
CAMLparam0(); | |
CAMLreturn(Val_int(x)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
external foo : unit -> unit = "foo_test" | |
external info : unit -> int = "foo_info" | |
let main () = | |
Printf.printf "counter before: %d\n%!" (info ()); | |
Bench.bench [("call c function", foo)]; | |
Printf.printf "counter after: %d\n%!" (info ()) | |
let _ = main () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment