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 KAA15935 for caml-red; Fri, 12 Jan 2001 10:03:31 +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 UAA05230 for ; Thu, 11 Jan 2001 20:14:43 +0100 (MET) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f0BJEgT10694 for ; Thu, 11 Jan 2001 20:14:43 +0100 (MET) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id UAA10756; Thu, 11 Jan 2001 20:14:26 +0100 (MET) Date: Thu, 11 Jan 2001 20:14:26 +0100 From: Markus Mottl To: Jacques Garrigue Cc: luther@dpt-info.u-strasbg.fr, caml-list@inria.fr Subject: Re: Cost of polymorphic variants over normal ones. Message-ID: <20010111201426.B2615@miss.wu-wien.ac.at> References: <200101101825.NAA17093@labrador.eecs.harvard.edu> <20010111101703.A3683@lambda.u-strasbg.fr> <20010111235041Z.garrigue@kurims.kyoto-u.ac.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010111235041Z.garrigue@kurims.kyoto-u.ac.jp>; from garrigue@kurims.kyoto-u.ac.jp on Thu, Jan 11, 2001 at 23:50:41 +0900 Sender: weis@pauillac.inria.fr > However I was surprised to see that with the native code compiler > polymorphic variants appeared to be faster than normal ones. That > seems to mean than on modern CPUs, an indirect jump is about 3 times > more expansive than a conditional, and that polymorphic variants are > only going to be slow on huge matches. But this was a single, very > simple benchmark, so I'm not sure this behaviour is stable. This is also in accordance with a test that I did a few years ago (in C++): I wondered whether it is more efficient to use function pointers (jump tables) or case switches to choose the next code part to be executed. I was surprised to find out that such tables only started paying off at numbers of around 100 alternatives (I certainly did this test on Intel chips, but if I remember correctly, it is also true for Alphas). I guess this may have to do with pipelining and/or cache effects. Processor experts can probably tell us more... - Markus Mottl -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl