Version française
Home     About     Download     Resources     Contact us    
Browse thread
gestion du temps en Caml ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: GillesDfnx@m...
Subject: Re: gestion du temps en Caml ?

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