From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL,HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 9E400BC6B for ; Tue, 9 Oct 2007 15:01:07 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAGsYC0fAXQInh2dsb2JhbACCOzaLVwIBCAop X-IronPort-AV: E=Sophos;i="4.21,248,1188770400"; d="scan'208,217";a="2652415" Received: from concorde.inria.fr ([192.93.2.39]) by mail1-smtp-roc.national.inria.fr with ESMTP; 09 Oct 2007 15:01:07 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l99D12eK015763 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 9 Oct 2007 15:01:06 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq4HAMcWC0dCm3xr/2dsb2JhbACCOzY X-IronPort-AV: E=Sophos;i="4.21,248,1188770400"; d="scan'208,217";a="2772577" Received: from www.janestcapital.com (HELO smtp.janestcapital.com) ([66.155.124.107]) by mail2-smtp-roc.national.inria.fr with ESMTP; 09 Oct 2007 14:52:12 +0200 Received: from [172.25.129.161] [38.96.172.125] by janestcapital.com with ESMTP (SMTPD-9.10) id A97B051C; Tue, 09 Oct 2007 08:52:11 -0400 Message-ID: <470B797A.3080904@janestcapital.com> Date: Tue, 09 Oct 2007 08:52:10 -0400 From: Brian Hurt User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: skaller Cc: Caml-list List Subject: Re: [Caml-list] Correct way of programming a CGI script References: <1191859489.10162.16.camel@localhost.localdomain> <1191879429.28011.27.camel@rosella.wigram> In-Reply-To: <1191879429.28011.27.camel@rosella.wigram> Content-Type: multipart/alternative; boundary="------------060704040308020408010002" X-Miltered: at concorde with ID 470B7B8E.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; 0200,:01 gerd:01 stolpmann:01 ocaml:01 gerd:01 recursive:01 ocaml:01 blit:01 0200,:01 stolpmann:01 recursive:01 blit:01 wrote:01 wrote:01 rec:01 This is a multi-part message in MIME format. --------------060704040308020408010002 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit skaller wrote: >On Mon, 2007-10-08 at 18:04 +0200, Gerd Stolpmann wrote: > > > >>>I heard that OCaml is particularly slow (and probably >>>memory-inefficient) when it comes to string manipulation. >>> >>> >>No, this is nonsense. Of course, you can slow everything down by using >>strings in an inappropriate way, like >> >>let rec concat_list l = >> match l with >> [] -> "" >> | s :: l' -> s ^ concat_list l' >> >> > >Now Gerd, I would not call the claim nonsense. If you can't >use a data structure in a natural way, I'd say the claim indeed >has some weight. > >The example above is ugly because it isn't tail recursive. >If you consider an imperative loop to concat the strings >in an array > > let s = ref "" in > for i = 0 to Array.length a do > s := !s ^ a.[i] > done; > >then Ocaml is likely to do this slowly. C++ on the other >hand will probably do this faster, especially if you reserve >enough storage first. > > And if you don't, and thus have to repeatedly allocate more memory, C++ is likely going to be slower than Ocaml (poor allocation performance). In fact, I'm willing to bet you can get near C++ speed by doing things in the C++ way- allocate the string once (with enough space), and then use String.blit to fill it in. That said, there are better implementations of strings for Ocaml. So what? Ocaml isn't a string processing language. Yeah, there are things which are probably better done in Perl/Python/Ruby. A language doesn't have to be the perfect language for all purposes in order to be a good language- in fact, in my experience languages that try to be everything to everybody end up being useless for all purposes (C++ being example #1 here). Brian --------------060704040308020408010002 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit skaller wrote:
On Mon, 2007-10-08 at 18:04 +0200, Gerd Stolpmann wrote:

  
I heard that OCaml is particularly slow (and probably
memory-inefficient) when it comes to string manipulation.
      
No, this is nonsense. Of course, you can slow everything down by using
strings in an inappropriate way, like

let rec concat_list l =
  match l with
    [] -> ""
  | s :: l' -> s ^ concat_list l'
    

Now Gerd, I would not call the claim nonsense. If you can't
use a data structure in a natural way, I'd say the claim indeed
has some weight.

The example above is ugly because it isn't tail recursive.
If you consider an imperative loop to concat the strings
in an array

	let s = ref "" in
	for i = 0 to Array.length a do
		s := !s ^ a.[i]
	done;

then Ocaml is likely to do this slowly. C++ on the other
hand will probably do this faster, especially if you reserve
enough storage first.
  

And if you don't, and thus have to repeatedly allocate more memory, C++ is likely going to be slower than Ocaml (poor allocation performance).  In fact, I'm willing to bet you can get near C++ speed by doing things in the C++ way- allocate the string once (with enough space), and then use String.blit to fill it in.

That said, there are better implementations of strings for Ocaml.  So what?  Ocaml isn't a string processing language.  Yeah, there are things which are probably better done in Perl/Python/Ruby.  A language doesn't have to be the perfect language for all purposes in order to be a good language- in fact, in my experience languages that try to be everything to everybody end up being useless for all purposes (C++ being example #1 here).

Brian

--------------060704040308020408010002--