English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Multiplication of matrix in C and OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-02-09 (13:50)
From: Brian Hurt <bhurt@j...>
Subject: Re: [Caml-list] Multiplication of matrix in C and OCaml

>I'd feel better if the code is benchmarked in a way
>that the result of the multiplication is output to a file and to
>subtract the constant contribution of that to the run time that the
>time is measured for various problem sizes (number of matrices). 

For the C side, I recommend using clock() to time the runs.  This also 
factors out the cost of creating the random matricies.  Basically, you 
just do:

#include <time.h>

        clock_t start, stop;
        start = clock();
        /* stuff to time here */
        stop = clock();
        printf("The amount of time taken = %f seconds\n", 
((double)(stop-start))/((double) CLOCKS_PER_SEC));
        /* write result to file */

In Ocaml, Unix.gettimeofday can be used similiarly:

    let start = Unix.gettimeofday() in
    (* stuff to time here *)
    let stop = Unix.gettimeofday() in
    Printf.printf "The amount of time taken = %f seconds\n" (stop -. start);
     (* write results to file *)