• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Relative Speed of using Lists vs Arrays

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Performance forum...
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic