|
From: <tri...@tr...> - 2004-02-27 21:50:00
|
Here is a quick unscientific benchmark:
JdbcTemplate jt = new JdbcTemplate(ds);
String sql = "select * from my_large_table where rownum <= 200000";
long start = System.currentTimeMillis();
List l = jt.queryForList(sql);
int x = 0;
for (int i = 0; i < l.size(); i++) {
x++;
}
long done = System.currentTimeMillis();
System.out.println(": " + x + " in " + (done - start) + "ms");
And the results:
java.util.LinkedList: 2000 in 1156ms
java.util.ArrayList: 2000 in 1156ms
java.util.LinkedList: 20000 in 5968ms
java.util.ArrayList: 20000 in 6031ms
java.util.LinkedList: 200000 in 52154ms
java.util.ArrayList: 200000 in 52639ms
As you can see the difference is very small. Most of the time is spent reading
the data from the database so the List processing only make up a tiny fraction
of the total time. I looked at the memory usage during the 200000 row runs and
these were the numbers:
java.util.LinkedList: [196MB]
java.util.ArrayList: [192MB]
Thomas
Quoting tri...@tr...:
> Eduardo,
>
> I assume that you mean the new JdbcTemplate.queryForList()
>
> It's an interesting question and I think the jury is still out on whether
> the
> Linked List or ArrayList would perform better here - I have seen arguments
> going
> both ways (if I have some extra time I will run some benchmarks for our
> specific
> use). A lot depends on the size of the resultset and I would not use this
> method for running a query returning a really large number of rows anyway.
> That
> said, I'd be happy to change it if there definitely is a performace
> difference.
>
> Thomas
>
>
> Quoting Eduardo Issao Ito <zi...@su...>:
>
> >
> > I noticed that JdbcHelper.queryForList() method returns an ArrayList, but a
>
> > LinkedList should not be more appropriate (more performant without need of
> > array
> > realocation as the list grows) as it is a generic funcition and the
> rowcount
> > is
> > not known in advance?
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >
>
>
>
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
|