You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Janek Bogucki <ja...@yahoo.co.uk> on 2001/12/15 00:47:52 UTC
ObjectUtils.deserialize (...): Suggested improvement
Hi,
I have a suggestion for improving the performance of
ObjectUtils.deserialize( byte[] objectData ). I did
some tests which showed improvement for the
deserialisation of a serialised Strings with the new
version.
Here are the figures with elapsed times in millis:
Time to deserialize "Hello World!" 1000*1000 times:
original new
21408 12186
21259 12134
Time to deserialize a String 10*000 chars long
100*1000 times:
original new
69611 66650
69412 67809
Time to deserialize a String 100*000 chars long
10*1000 times:
original new
122917 122837
123742 122635
The change to get this improvement is to omit the
BufferedInputStream object as buffering won't be of
any benefit when the data is already in RAM.
(I also dropped the bin.close () invocation as this is
unneccesary since in.close () invokes bin.close ()
automatically.)
Many Thanks,
Janek Bogucki
Improved version
----------------
/**
* Deserializes a single object from an array of
bytes.
*
* @param objectData The serialized object.
* @return The deserialized object, or
<code>null</code> on failure.
*/
public static Object deserialize ( byte[]
objectData ) {
Object object = null;
if (objectData != null) {
// These streams are closed in finally.
ObjectInputStream in = null;
ByteArrayInputStream bin =
new ByteArrayInputStream (objectData) ;
try {
in = new ObjectInputStream (bin);
// If objectData has not been
initialized, an
// exception will occur.
object = in.readObject ();
}
catch (Exception e) {
}
finally {
try {
if (in != null) in.close ();
}
catch(IOException e) {
}
}
}
return object;
}
__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: ObjectUtils.deserialize (...): Suggested improvement
Posted by Daniel Rall <dl...@finemaltcoding.com>.
Janek Bogucki <ja...@yahoo.co.uk> writes:
> I have a suggestion for improving the performance of
> ObjectUtils.deserialize( byte[] objectData ). I did
> some tests which showed improvement for the
> deserialisation of a serialised Strings with the new
> version.
[snip]
Committed with minor modifications, thanks Janek.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>