[Haskell-cafe] performance question

John Meacham john at repetae.net
Tue Jan 18 05:15:50 EST 2005


On Mon, Jan 17, 2005 at 08:54:38PM -0800, Ben Rudiak-Gould wrote:
> If performance is the main concern, I would flatten the data structure:
> 
>    data Interval = IlII Double Double
>                  | IlIE Double Double
>                  | IlEI Double Double
>                  | IlEE Double Double
>                  | NilII Double Double
>                  | NilIE Double Double
>                  | NilEI Double Double
>                  | NilEE Double Double

I would go even further 

>    data IntervalType = IlII 
>                  | IlIE 
>                  | IlEI 
>                  | IlEE 
>                  | NilII
>                  | NilIE
>                  | NilEI
>                  | NilEE
>    data Interval = Interval IntervalType {-# UNPACK #-} !Double {-# UNPACK #-} !Double

now, the doubles can be stored in their native form and are not under a
union data type (which always must be represented by a pointer) so
accessing them can be very fast.

        John


-- 
John Meacham - ⑆repetae.net⑆john⑈ 


More information about the Haskell-Cafe mailing list