directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Karasulu" <aok...@bellsouth.net>
Subject RE: [bdbje] [rms] Using int verses Integer and native key/value ordering
Date Mon, 19 Apr 2004 18:18:28 GMT
Hey Mark,

Thanks for the response.

> -----Original Message-----
> From: Mark Hayes [mailto:mark@sleepycat.com]

> Your questions on this have me thinking about a possible addition to
> our binding API.  Currently, TupleBinding has a static method,
> getPrimitiveBinding, that returns a binding for a given primitive
> wrapper class.  As an alternative, we could expose the (currently
> private) IntegerBinding, FloatBinding, etc, classes, and add methods to
> those classes that take "int", "float", etc, types.
> 
> Do you think that would be a worthwhile addition?  I'm not promising
> that we would do this, as I'm sure you understand, but I'm very
> interested in your opinion.

Funny you mention that because I took these methods (just for the 
primitive int for now) and stuffed a copy of them into a utility 
class JePrimitiveCodecs.java which is attached.  You probably know 
what's in there better than anyone :-).  Basically this is how I 
tested the primitive verses wrapper approach.  Here's what the code 
looks like the variable 'b' btw is the binding gotten via 
TupleBinding.getPrimitiveBinding(Integer.class):

-- USING PRIMITIVES --

    public void testIntStress() throws Exception
    {
        for ( int ii = 10000; ii >= 0; ii-- )
        {
            if ( ii % 1000 == 0 )
            {
                System.out.print( "." ) ;
            }

            JePrimitiveCodecs.encodeInt( ii, key ) ;
            JePrimitiveCodecs.encodeInt( ii, value ) ;
            db.put( null, key, value ) ;

            JePrimitiveCodecs.encodeInt( ii + 1, value ) ;
            db.put( null, key, value ) ;

            JePrimitiveCodecs.encodeInt( ii + 2, value ) ;
            db.put( null, key, value ) ;

            JePrimitiveCodecs.encodeInt( ii + 3, value ) ;
            db.put( null, key, value ) ;

            JePrimitiveCodecs.encodeInt( ii + 4, value ) ;
            db.put( null, key, value ) ;

            JePrimitiveCodecs.encodeInt( ii + 5, value ) ;
            db.put( null, key, value ) ;
        }
    }

-- USING OBJECT WRAPPERS --

    public void testIntegerStress() throws Exception
    {
        for ( int ii = 10000; ii >= 0; ii-- )
        {
            if ( ii % 1000 == 0 )
            {
                System.out.print( "." ) ;
            }

            Integer wrapper = new Integer( ii ) ;
            b.objectToEntry( wrapper, key ) ;

            b.objectToEntry( wrapper, value ) ;
            db.put( null, key, value ) ;

            b.objectToEntry( new Integer( ii + 1 ), value ) ;
            db.put( null, key, value ) ;

            b.objectToEntry( new Integer( ii + 2 ), value ) ;
            db.put( null, key, value ) ;

            b.objectToEntry( new Integer( ii + 3 ), value ) ;
            db.put( null, key, value ) ;

            b.objectToEntry( new Integer( ii + 4 ), value ) ;
            db.put( null, key, value ) ;

            b.objectToEntry( new Integer( ii + 5 ), value ) ;
            db.put( null, key, value ) ;
        }
    }

Now after my tests showed a nominal 7% improvement using primitives 
over wrappers I realized this was stupid of me to do.  However you'll 
hear this argument over and over again and not every one is going to 
test this out.  They'll complain about though :-).  Might save you an 
email or two just to expose it - that's my take now that I have the 
numbas after the stress tests.  Plus it just completes the picture.

BTW your Binding API's are very nice - I like them.  It would be 
nice to have such an API in general.  I see many incarnations out 
there like the Jakarta-commons convert project in the sandbox, but 
none are as simple and intuitive as this one.  

Alex



Mime
View raw message