Performance Characteristics of com.sas.collection Classes

This page provides a guide on the performance characteristics of some of the collections in the com.sas.collection package. You can use this information to help decide which collection to use for various needs.

SAS Collections vs Java 2 Collections

One important note about the com.sas.collection package is that you may not need to use it at all. This package was written before the new Java 2 collection classes, when Java had only Vector and Hashtable. Also, the SAS collection hierarchy was designed to meet many needs, including serving as models for many visual components. Thus, the SAS collections are more heavyweight than the newer Java 2 collections:

  1. the SAS collections are almost all synchronized
  2. the SAS collection implementations extend com.sas.Component
  3. the SAS collection classes can fire ContentsChangedEvents when the collection is modified.

Thus, in many cases, you may want to consider using Java 2 collections instead of the SAS collection framework. For example, you should avoid using the SAS collections for "internal" implementations that are hidden from your class' clients.

Performance Characteristics

The below table shows some of the performance characteristics for some of the SAS collections. The performance of each operation is expressed in "big O" notation.

SAS Collections

Class

get(index)

get(key)

iterate

contains

insert

append

remove

AssociationList 1

O(1)

O(n)

O(1)

O(n)

O(1)

O(1)

O(1)

Collection 2

N/A

N/A

O(1)

O(n)

O(1)

O(1)

O(n)

Dictionary

N/A

O(1)

O(1)

O(1)

O(1)

O(1)

O(1)

OrderedCollection 3

O(1)

N/A

O(1)

O(n)

O(1)

O(1)

O(1)

OrderedListCollection

O(n)

N/A

O(1)

O(n)

O(1)

O(1)

O(1)

PropertyBag 4

N/A

O(n)

N/A

O(n)

N/A

O(1)

O(n)

Queue

N/A

N/A

N/A

N/A

N/A

O(1)

O(1)

Set

O(1)

N/A

O(1)

O(1)

O(1)

O(1)

O(1)

SortedCollection

O(1)

N/A

O(1)

O(log n)

O(log n)

O(log n)

O(log n)

Table Key

get
retrieve an item from the list. For lists, this involves a get(int index) operation for random indices; for dictionaries, it is get(Object key)
iterate
move through the collection in its natural order. For lists, this involves iterating from index = 0 to collection.count()-1
contains
test if the collection contains an object
insert
insert an item into the collection
append
add an item to the "end of" the collection.
remove
remove an item from the collection. The item to be removed is specified by the index (for lists) or the key (for dictionaries), as specified by the get operation. The collections also support remove methods which take the object to be removed as a parameter; the performance of this operation is typically the sum of the contains and remove method.

Notes

1 AssociationList has constructors for specifying the internal implementation. These metrics assume the default, OrderedCollection, implementation.

2 Collection supports either collection semantics (allowing duplicates) or set semantics (no duplicates). These metrics assume collection semantics; the Collection is implemented with an OrderedCollection. The metrics for Set assume set semantics (implemented with a disctionary)

3 OrderedCollection also includes '

4 Although PropertyBag has O(n) behavior, the constant is extremely small and for small property bags, its O(n) behavior is often better than hashtable based collections with O(1) performance but with higher constants. Also, PropertyBag is not synchronized