Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 59728 invoked from network); 14 Dec 2001 23:47:51 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 14 Dec 2001 23:47:51 -0000 Received: (qmail 3603 invoked by uid 97); 14 Dec 2001 23:47:56 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 3549 invoked by uid 97); 14 Dec 2001 23:47:55 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 3538 invoked from network); 14 Dec 2001 23:47:55 -0000 Message-ID: <20011214234752.25410.qmail@web20904.mail.yahoo.com> Date: Fri, 14 Dec 2001 23:47:52 +0000 (GMT) From: =?iso-8859-1?q?Janek=20Bogucki?= Subject: ObjectUtils.deserialize (...): Suggested improvement To: commons-dev@jakarta.apache.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 null 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: For additional commands, e-mail: