Re: gestion du temps en Caml ?

From: GillesDfnx@mail.dotcom.fr
Date: Thu Feb 19 1998 - 18:27:38 MET


From: GillesDfnx@mail.dotcom.fr
Date: Thu, 19 Feb 1998 18:27:38 +0100 (MET)
Message-Id: <199802191727.SAA07001@cosmos.imag.fr>
To: caml-light mailing list <caml-light@pauillac.inria.fr>
Subject: Re: gestion du temps en Caml ?
In-Reply-To: <199802191634.RAA26446@pauillac.inria.fr>
 <199802191634.RAA26446@pauillac.inria.fr>

Pour Objective caml et unix : il existe la fonction C clock (3), qui a
chaque appel retourne le temps ecoule depuis le dernier appel.

For Objective caml and unix : there exists a C function, clock (3),
that returns the elapsed time since last call.

(* Fichier clock.mli *)

external clock : unit -> int = "myclock"

/* Fichier clock.c */

#include <stdlib.h>
#include <time.h>
#include <mlvalues.h>

value myclock (unit)
        value unit;
{
  long i;
  i = clock() / CLOCKS_PER_SEC; /* Number of seconds */
  return Val_long (i);
}

(* Fichier test.ml *)

open Clock

let rec fibo = function
    0 -> 1
  | 1 -> 1
  | n -> fibo (n - 1) + fibo (n - 2);;

let _ =
  let _ = clock ()
  in let n = fibo 35
  in let time = clock ()
  in print_int time ; print_newline () ; n;;

(* Fin *)

$ make
ocamlc -c clock.mli
gcc -c -I/usr/lib/ocaml/caml clock.c
ocamlc -c test.ml
ocamlc -custom -o test unix.cma test.cmo clock.o -cclib -lunix
time -f "%e" ./test
14
14.46
$

-- 
                                                \\///
#use "std.disclaimer"                           (O O)
--------------------------------------------oOo--(_)--oOo--------
Gilles DEFOURNEAUX            \ /
Automated Deduction Team       |
ATINF project - LEIBNIZ lab  --|--
Grenoble, FRANCE               0    GillesDfnx@mail.dotcom.fr



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:13 MET