caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: kirillkh <kirillkh@gmail.com>
To: "Daniel de Rauglaudre" <daniel.de_rauglaudre@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Re: Locally-polymorphic exceptions [was: folding over a file]
Date: Wed, 3 Oct 2007 16:34:51 +0200	[thread overview]
Message-ID: <e2d02be30710030734l7420cd84p315effb07be322a2@mail.gmail.com> (raw)
In-Reply-To: <20071003123201.GA3833@yquem.inria.fr>

[-- Attachment #1: Type: text/plain, Size: 1676 bytes --]

2007/10/3, Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>:
>
> Hi,
>
> On Wed, Oct 03, 2007 at 02:19:56PM +0200, kirillkh wrote:
>
> > But then someone suggested using a second exception instead, which
> > is better performance-wise [...]
>
> Is that been checked ? And the two implementations tested ? What are the
> results, in time ?
>

Tested from the top-level on a text file with 11mln lines:
variants:
8.081  8.021  8.072  8.052  8.011  =>  avg=8.0474
exceptions:
7.801  7.902  7.822  7.901  7.832  =>  avg=7.8512
-----------------------------
total: exceptions are 2.44% faster

I'm having troubles with ocamlopt (windows machine), can anyone do a similar
test with it? Here's the code used (it's the pre-combinator version of line
counter):

exceptions (lcex.ml):
exception Done of int;;

let line_count filename =
 let file = open_in filename in
 let rec loop count =
   let _ =
     try
       input_line file
     with End_of_file -> raise (Done count)
   in
     loop (count + 1)
 in
   try loop 0 with Done x -> x
;;

let start_time = Sys.time() in
let count = line_count "c:/kirill/ocaml/test3.txt" in
let diff = Sys.time() -. start_time in
    Printf.printf "count: %d,  time: %f" count diff;;

variants(lcvar.ml):
let readline f =
  try Some (input_line f)
  with End_of_file -> None;;

let line_count filename =
  let f = open_in filename in
  let rec loop count =
    match (readline f) with
      | Some(_) -> loop (count+1)
      | None -> count in
  loop 0;;

let start_time = Sys.time() in
let count = line_count "c:/kirill/ocaml/test3.txt" in
let diff = Sys.time() -. start_time in
    Printf.printf "count: %d,  time: %f" count diff;;


-Kirill

[-- Attachment #2: Type: text/html, Size: 2679 bytes --]

  reply	other threads:[~2007-10-03 14:34 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-03  8:35 oleg
2007-10-03 11:27 ` kirillkh
2007-10-03 11:48   ` [Caml-list] " Daniel de Rauglaudre
2007-10-03 12:19     ` kirillkh
2007-10-03 12:32       ` Daniel de Rauglaudre
2007-10-03 14:34         ` kirillkh [this message]
2007-10-03 20:39   ` Christophe Raffalli
2007-10-03 22:50     ` Unsoundness is essential skaller
2007-10-03 23:13       ` [Caml-list] " Jacques Carette
2007-10-04  1:24         ` skaller
2007-10-04 11:26           ` David Allsopp
2007-10-04 12:45             ` Vincent Hanquez
2007-10-04 15:07               ` skaller
2007-10-03 23:13       ` Vincent Aravantinos
2007-10-04  1:49         ` skaller
2007-10-03 23:28       ` Joshua D. Guttman
2007-10-04  1:52         ` skaller
2007-10-04  2:35           ` Brian Hurt
2007-10-04  7:46           ` Christophe Raffalli
2007-10-04  8:56             ` Arnaud Spiwack
2007-10-04 14:49               ` skaller
2007-10-04 15:00                 ` Harrison, John R
2007-10-04 15:29                 ` Andrej Bauer
2007-10-04 16:25                   ` skaller
2007-10-04 18:17                     ` Arnaud Spiwack
2007-10-04 20:54                       ` skaller
2007-10-04 22:24                         ` Arnaud Spiwack
2007-10-04 16:37                   ` skaller
2007-10-04 18:59                     ` Christophe Raffalli
2007-10-04 15:04               ` Andrej Bauer
2007-10-04 15:57                 ` Christophe Raffalli
2007-10-04 16:03                 ` skaller
2007-10-04 20:02                   ` Ken Rose
2007-10-04 21:00                     ` skaller
2007-10-04 15:31       ` Lukasz Stafiniak
2007-10-04 17:56       ` rossberg
2007-10-04 19:56         ` skaller
2007-10-04 21:07           ` rossberg
2007-10-04 22:23             ` skaller
2007-10-05  2:48               ` Bárður Árantsson
2007-10-04  2:16   ` Locally-polymorphic exceptions [was: folding over a file] oleg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e2d02be30710030734l7420cd84p315effb07be322a2@mail.gmail.com \
    --to=kirillkh@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=daniel.de_rauglaudre@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).