I'm running some simple, rudimentary benchmarking just to see how Generics impact performance. I'm certainly not a "generics" programmer so this is all based on my own experimentation...nothing concrete.
It would appear, in my case anyhow, that generics can definitely impact performance in a negitive way. If this is obvious to folks that are more familiar w/ them...then I apologize for stating the obvious.
I'm building my own blog application using
J2EE + db4o (object database) and I wanted to use a generic method to convert the "ObjectSet" collection that db4o returns when querying the database into an ArrayList collection of my own object datatype...so as to be able to "bind" to a JSTL loop statement in a
JSP.
Here's a couple of snippets to illustrate. I realize readers may not be familiar w/ db4o but these examples are so simple, any programmer could follow it.
db4o will return an ObjectSet when querying objects; Here is me querying the default "Blog" class for its entries (Entry class):
If I iterate through this ObjectSet collection reading one of the fields...it takes about 239 milliseconds with roughly 50,000 records.
Now, I created this generic method to pass in the Object set and create a List<IEntry> collection so I could have a collection that is usable in JSTL (can't remember which interface makes this possible, I'm new to
Java!)
Example:
I use this method to convert the ObjectSet to a List like so:
Executing this in a loop the same as the aforementioned, ObjectSet-based collection takes about 750ms - more than double the amount of time.
Any advice?
Thanks!
-v