From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA01227; Tue, 19 Nov 2002 23:26:56 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA01223 for caml-list@pauillac.inria.fr; Tue, 19 Nov 2002 23:26:55 +0100 (MET) 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 TAA29370 for ; Tue, 19 Nov 2002 19:39:04 +0100 (MET) Received: from students.mimuw.edu.pl (zodiac.mimuw.edu.pl [193.0.96.128]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gAJId3118088 for ; Tue, 19 Nov 2002 19:39:03 +0100 (MET) Received: from localhost (localhost [127.0.0.1]) by students.mimuw.edu.pl (Postfix) with ESMTP id 1DB7517A5E for ; Tue, 19 Nov 2002 19:38:58 +0100 (CET) Received: by students.mimuw.edu.pl (Postfix, from userid 2733) id 6EA8917A57; Tue, 19 Nov 2002 19:38:57 +0100 (CET) Date: Tue, 19 Nov 2002 19:38:57 +0100 From: Cezary Kaliszyk To: caml-list@inria.fr Subject: [Caml-list] Objects poor performance Message-ID: <20021119183857.GB15185@zodiac.mimuw.edu.pl> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="p4qYPpj5QlsIQJ0K" Content-Disposition: inline User-Agent: Mutt/1.3.27i X-Virus-Scanned: by AMaViS new-20020517 X-Razor-id: ac319e593a2045755311aa139d1013f997c35dc3 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk --p4qYPpj5QlsIQJ0K Content-Type: multipart/mixed; boundary="zYM0uCDKw75PZbzx" Content-Disposition: inline --zYM0uCDKw75PZbzx Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable I tried to implement a simple double-linked list with constant time inserti= on and removal. I tried just iterating over such a list with both object and structure implementation. And these are the effects: Time: Structures: 2.503s Objects: 27.027s The implementations are the same so why are objects that slow? I include the tests if someone wishes to test oneself or see if anything can be done faster. PS. The size of stripped executable is also 2*larger with objects. But that's not such a big problem. --=20 --zYM0uCDKw75PZbzx Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: attachment; filename="object.ml" Content-Transfer-Encoding: quoted-printable class ['a] lst data =3D=20 object val mutable data =3D (data : 'a) val mutable prev =3D ((Obj.magic ()) : 'a lst) val mutable next =3D ((Obj.magic ()) : 'a lst) method add new_data =3D=20 new lst new_data in new_elem#set_next next; new_elem#set_prev (next#get_prev); next#set_prev new_elem; next <- new_elem method get_prev =3D prev method get_next =3D next method set_prev elem =3D prev <- elem method set_next elem =3D next <- elem method get =3D data end ;; =20 let l =3D new lst (0, 0);; l#set_next l;; l#set_prev l;; let rec adder cnt =3D l#add (cnt, 0); if cnt > 0 then adder (cnt - 1) in adder 1000;; let rec iterator a cnt alst =3D if cnt =3D 0 then a else let (i, _) =3D alst#get in iterator (a + i) (cnt - 1) alst#get_next ;; =20 let rec test cnt =3D ignore (iterator 0 1000 l); if cnt =3D 0 then () else test (cnt - 1) ;; =20 test 1000000;; --zYM0uCDKw75PZbzx Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: attachment; filename="struct.ml" Content-Transfer-Encoding: quoted-printable type 'a ts =3D { mutable data : 'a; mutable prev : 'a ts; mutable next : 'a ts; };; =20 let rec single elem =3D let ret =3D { data =3D elem;=20 next =3D Obj.magic 0; prev =3D Obj.magic 0; } in ret.next <- ret; ret.prev <- ret; ret ;; let rec add elem ({next =3D n} as lst) =3D let newnext =3D { data =3D elem; prev =3D lst; next =3D n } in n.prev <- newnext; lst.next <- newnext ;; let l =3D single (0, 0);; =20 let rec adder cnt =3D add (cnt, 0) l; if cnt > 0 then adder (cnt - 1) in adder 1000;; =20 let rec iterator a cnt alst =3D if cnt =3D 0 then a else let (i, _) =3D alst.data in iterator (a + i) (cnt - 1) alst.next ;; =20 let rec test cnt =3D ignore (iterator 0 1000 l); if cnt =3D 0 then () else test (cnt - 1) ;; test 1000000;; --zYM0uCDKw75PZbzx-- --p4qYPpj5QlsIQJ0K Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: Dalsze informacje znajdują się na http://www.gnupg.org/ iD8DBQE92oVBYfPl1pqp6/URAhHHAKCWowN+zSowe6TIU6GowAGRNdS/WACbBdOc QX1Kilyj2T6v15fLS06Qcc0= =Im9f -----END PGP SIGNATURE----- --p4qYPpj5QlsIQJ0K-- ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners