Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: Pervasives.compare: slow?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Ruchira Datta <datta@m...>
Subject: Re: Pervasives.compare: slow?

David Monniaux wrote:

>Pervasives.compare is a polymorphic hack ...
>There is apparently a 20-25% performance penalty using this form instead
>of a simple comparison procedure for 16-byte strings. I suspect the
>performance hit is even higher for more complex data structures.

On p. 359 of _ML for the Working Programmer_, Paulson defines a function

fun member (x:string, l) = List.exists (fn y => x=y) l;

On the next page he says,

"The functor declares function member for internal use....  The membership
test is specific to type string because polymorphic equality can be slow."

He seems to imply that in Standard ML, if the type of the things being
compared is specified beforehand, then a type-specific comparison is used.
I don't know if something similar holds in Objective Caml.

Ruchira Datta
datta@math.berkeley.edu