• Post Reply Bookmark Topic Watch Topic
  • New Topic

Relative Speed of using Lists vs Arrays  RSS feed

 
Mervin Chan
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any link where there are comparisons between storing objects in lists, arrays ?

Comparisons in terms of speed.

Thanks?
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer this question properly, you really need to have a context for the usage of the data structure. For example:

Is there more writing or reading?
Is there any searching?
Is there any random access to the List?

And most importantly, what list implementation vs array?

I'm sure there is information out there that tells you the realtive efficiencies of different list implementations in different situations, but I thought I'd just jump straight in with what was in my head.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Performance forum...
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would guess for most applications that the performance difference between the two is academic. I use both lists and arrays all the time and both are very fast. Lists are backed by arrays, so they will be no faster than arrays.

I have a demo program that does the following and times the performance
1) Converts the ResultSet to an ArrayList,
2) Converts the ArrayList to an Object[][] array.

If you run go to this page you can run this program:
SQL query/sort page

You can see the performance numbers in the following report.

JAMon Performance Report


1) com.fdsapi.ResultSetUtils.resultSetToList() - times performance of converting a ResultSet to an ArrayList
2) com.fdsapi.ResultSetUtils.listToObjectArray() - times performance of converting the ArrayList to an Object[][]

As you can see both are very fast, and 2) is so fast that it is difficult to time.

I would make my choice of whether to use a List or an array based on other criteria besides performance.
 
Chit Ming Chong
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I once use the the stardard java api to do simple test for performance. Time in java is measured in milliseconds; therefore, I just get a time before and after a function, I can roughly know the performance.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chit Ming Chong:
I once use the the stardard java api to do simple test for performance. Time in java is measured in milliseconds; therefore, I just get a time before and after a function, I can roughly know the performance.

Behind the scenes that is exactly what the jamon (Java Application Monitor) report mentioned above is doing.
[ March 10, 2005: Message edited by: steve souza ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!