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 autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 32B7CBC6B for ; Tue, 9 Oct 2007 01:42:55 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAACZdCkfAXQImh2dsb2JhbACORQEBAQgKKQ X-IronPort-AV: E=Sophos;i="4.21,245,1188770400"; d="scan'208";a="17608228" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 09 Oct 2007 01:42:54 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l98Ngqnk030388 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 9 Oct 2007 01:42:54 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAD9cCkfLENaMnmdsb2JhbACORQEBAQEHBAYRGA X-IronPort-AV: E=Sophos;i="4.21,245,1188770400"; d="scan'208";a="2470745" Received: from ipmail01.adl2.internode.on.net ([203.16.214.140]) by mail1-smtp-roc.national.inria.fr with ESMTP; 09 Oct 2007 01:42:50 +0200 X-IronPort-AV: E=Sophos;i="4.21,245,1188743400"; d="scan'208";a="206603076" Received: from ppp121-44-36-108.lns10.syd7.internode.on.net (HELO [192.168.1.201]) ([121.44.36.108]) by ipmail01.adl2.internode.on.net with ESMTP; 09 Oct 2007 09:07:50 +0930 Subject: Re: [Caml-list] Correct way of programming a CGI script From: skaller To: caml-list@inria.fr In-Reply-To: <20071009082147.657017dc.mle+ocaml@mega-nerd.com> References: <1191859489.10162.16.camel@localhost.localdomain> <1191879429.28011.27.camel@rosella.wigram> <20071009082147.657017dc.mle+ocaml@mega-nerd.com> Content-Type: text/plain Date: Tue, 09 Oct 2007 09:37:49 +1000 Message-Id: <1191886669.26491.29.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 470AC07C.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; gerd:01 ocaml:01 ocaml:01 buffer:01 buffer:01 'string:01 const':01 python's:01 sourceforge:01 wrote:01 wrote:01 caml-list:01 functions:01 immutable:01 imperative:01 On Tue, 2007-10-09 at 08:21 +1000, Erik de Castro Lopo wrote: > skaller wrote: > > > 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 original claim was: > > >> I heard that OCaml is particularly slow (and probably memory-inefficient) > >> when it comes to string manipulation. What is the preferred way in handling > >> strings (building long strings from short parts - something StringBuilder > >> would be used in Java)? Does anybody have any experience concerning this > >> kind of applications? > > ie comparing Ocaml string handling to Java and other web languages like > php, perl, ruby and python. > > While I agree that yes, it is possible to write slow code in Ocaml > (or any other language), I suspect that idiomatic Ocaml string handling > compiled to a binary is just as fast if not faster than Java/Perl/Python/ > Ruby/PHP/whatever. So, as shown in other posts, Ocaml really is SLOW with strings. But here Erik says 'idiomatic'. I haven't tested this, but again, this is probably wrong. If you use Buffer for concatenation you'll get faster times than Ocaml (^) operator on strings, but what this misses is that other operations on strings (such as searching, substring etc etc) aren't available for Buffer. So in order to use these you'd have to a) make a Buffer and add string into it b) get the string OUT of the buffer c) call the functions d) puts stuff back into some Buffer This is not only extremely ugly because it is mixing functional and imperative code .. it is probably as slow as two wet weeks because of the conversions back and forth. C++ strings on the other hand combine access to many operations, both functional and mutations, and automatically provide the 'Buffer'ing functionality as well. Unlike Buffer, however, they're passed by value so that 'string const' data type is purely functional. Note that Python strings are immutable, so surprisingly of all the languages I considered .. Python's string operations are actually purely functional. -- John Skaller Felix, successor to C++: http://felix.sf.net