From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA29795 for caml-redistribution; Wed, 6 Oct 1999 16:16:33 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA11166 for ; Tue, 5 Oct 1999 22:21:15 +0200 (MET DST) Received: from beach.frankfurt.netsurf.de (beach.frankfurt.netsurf.de [194.64.181.2]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id WAA17613 for ; Tue, 5 Oct 1999 22:21:13 +0200 (MET DST) Received: from ice.darmstadt.netsurf.de (board-86.darmstadt.netsurf.de [194.163.86.214]) by beach.frankfurt.netsurf.de (8.8.5/8.8.5) with ESMTP id WAA19146 for ; Tue, 5 Oct 1999 22:21:12 +0200 (MET DST) Received: from localhost (localhost [[UNIX: localhost]]) by ice.darmstadt.netsurf.de (8.9.3/8.9.3) id WAA17578 for caml-list@inria.fr; Tue, 5 Oct 1999 22:21:08 +0200 From: Gerd Stolpmann Reply-To: Gerd.Stolpmann@darmstadt.netsurf.de Organization: privat To: caml-list@inria.fr Subject: Re: speed versus C Date: Tue, 5 Oct 1999 22:20:59 +0200 X-Mailer: KMail [version 1.0.21] Content-Type: text/plain References: <000f01bf0de7$2f626fd0$240cbed4@jannt> MIME-Version: 1.0 Message-Id: <99100522193302.17263@ice> Content-Transfer-Encoding: 8bit Sender: weis On Sun, 03 Oct 1999, Jan Brosius wrote: >Hi, is there anything known about the efficiency of compiled Ocaml code >compared with C/C++ A good comparision of the low-level features of Ocaml and C are my implementations of the cryptographic algorithms Blowfish and DES. Such algorithms do many integer calculations, bit shifting, and array lookups, i.e. tasks where C is perfect, and Ocaml is not designed for. The manually optimized algorithms are 8 to 10 times slower than the C counterparts, and a factor of 2 can be explained with Ocaml's problems when computing with 32 bit numbers. To get around this, all 32 bit calculations are simulated by doing them on two 16 bit halves. If such problems do not play a role, Ocaml is at most 4 to 5 times slower than C. As already pointed out, Ocaml is not designed for such problems, and this slow-down factor is an upper limit. The typical application will have a speed which is comparable with C/C++ solutions, as there are a number of advantages: - The recursive data types of Ocaml are often more problem-oriented than "imperative" data structures. Consider you want to fill an (C) array with an unknown number of elements. The typical solution puts the elements into the array until it is full, and then enlarges the array by reallocating new memory. If you use the Ocaml lists instead, you do not have this problem. Of course, you can program linked lists in C, too, but they are not as convenient as arrays are, so many people avoid them. I think this is a very common problem in C where algorithms on static structures are cheap, and algorithms working with dynamic structures are either complicated (but fast), or calculate the same several times (but are simple to understand), or use sophisticated but heavy-weight libraries (with a complex interface). This is a bad alternative. Considering all of simplicity, time and space comsumption, I would say that Ocaml scales better. - OCaml code expresses the same with fewer lines of code, so it is possible to write more complicated solutions, and to prefer a more sophisticated approach over the straight-forward solution. - Memory management is much better; but this counts only for long-running applications. Many C/C++ programs only "malloc" and do not "free", so the time consumption of these functions isn't a problem. Gerd -- ---------------------------------------------------------------------------- Gerd Stolpmann Telefon: +49 6151 997705 (privat) Viktoriastr. 100 64293 Darmstadt EMail: Gerd.Stolpmann@darmstadt.netsurf.de (privat) Germany ----------------------------------------------------------------------------