Introduction des fonctions de timing.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1875 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Pierre Weis 1998-02-25 10:20:38 +00:00
parent 85bae36901
commit b5ae8a0a0a
3 changed files with 27 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#if !macintosh
#include <sys/types.h>
#include <sys/stat.h>
@ -27,6 +28,9 @@
#ifdef HAS_UNISTD
#include <unistd.h>
#endif
#ifdef HAS_TIMES
#include <sys/times.h>
#endif
#include "alloc.h"
#include "debugger.h"
#include "fail.h"
@ -214,6 +218,25 @@ value sys_system_command(value command) /* ML */
return Val_int(retcode);
}
value sys_time(value unit) /* ML */
{
#ifdef HAS_TIMES
#ifndef CLK_TCK
#ifdef HZ
#define CLK_TCK HZ
#else
#define CLK_TCK 60
#endif
#endif
struct tms t;
times(&t);
return copy_double((double)(t.tms_utime + t.tms_stime) / CLK_TCK);
#else
/* clock() is standard ANSI C */
return copy_double((double)clock() / CLOCKS_PER_SEC);
#endif
}
value sys_get_config(value unit) /* ML */
{
value result;

View File

@ -26,6 +26,7 @@ external remove: string -> unit = "sys_remove"
external rename : string -> string -> unit = "sys_rename"
external getenv: string -> string = "sys_getenv"
external command: string -> int = "sys_system_command"
external time: unit -> float = "sys_time"
external chdir: string -> unit = "sys_chdir"
external getcwd: unit -> string = "sys_getcwd"

View File

@ -29,6 +29,9 @@ external getenv: string -> string = "sys_getenv"
environment. Raise [Not_found] if the variable is unbound. *)
external command: string -> int = "sys_system_command"
(* Execute the given shell command and return its exit code. *)
external time: unit -> float = "sys_time"
(* Return the processor time, in seconds, used by the program
since the beginning of execution. *)
external chdir: string -> unit = "sys_chdir"
(* Change the current working directory of the process. *)
external getcwd: unit -> string = "sys_getcwd"