Browse thread
Correct way of programming a CGI script
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | skaller <skaller@u...> |
| Subject: | Re: [Caml-list] Correct way of programming a CGI script |
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 <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net