JGL is a high performance library whose containers and algorithms meet or beat the performance of existing libraries. In addition, the JGL algorithms are generally at least as fast as their hand-coded equivalents. The JGL installation includes the following set of benchmarks:
\jgl_1_1
\benchmarks
ArrayBenchmarks.java Compares JGL Array against JDK Vector
MapBenchmarks.java Compares JGL Map against JDK Hashtable
SortingBenchmarks.java Compares JGL sort() against hand-coded quicksort
*.txt Sample benchmarks
and then run them by enteringjvc *.java
Each of these programs uses the Benchmark class to perform timing comparisons, and display intermediate benchmarks as they are gathered. The final performance ratio is displayed at the end of each benchmark. A ratio of less than 1.0 means that JGL ran faster. A sample run of these benchmarks is included in the filesjview ArrayBenchmarks
jview MapBenchmarks
jview SortingBenchmarks
*.txt.
A summary of these files is included on the next page.
Please note that random variations in the garbage
collection system can cause significant variance in an individual
performance statistic. The performance claims that we make for
JGL are based on an average of large numbers of measurements.
SAMPLE BENCHMARKS
-----------------
These benchmarks were run on a Toshiba Tecra computer with
32Mb RAM running Windows 95 and JDK 1.0.2.
A ratio of less than 1.0 means that JGL ran faster.
ArrayBenchmarks.txt
-------------------
ratio of jglArrayGetting to jdkVectorGetting is 0.850775
ratio of jglArrayPutting to jdkVectorPutting is 1.21103
ratio of jglArrayIterating to jdkVectorIterating is 1.12203
ratio of jglArrayAdding to jdkVectorAdding is 0.715431
ratio of jglArrayClearing to jdkVectorClearing is 0.204819
ratio of jglArrayInserting to jdkVectorInserting is 1.02515
ratio of jglArrayRemoving to jdkVectorRemoving is 0.980042
MapBenchmarks.txt
-----------------
ratio of jglMapAdding to jdkHashtableAdding is 0.983074
ratio of jglMapFinding to jdkHashtableFinding is 1.00821
ratio of jglMapRemoving to jdkHashtableRemoving is 1.02933
ratio of jglMapClearing to jdkHashtableClearing is 0.44186
SortingBenchmarks.txt
---------------------
ratio of jgl sort algorithm to handcoded sorting is 1.04997
This section lists the differences between JGL and STL as well as a side-by-side comparison of JGL and STL code segments.
Here is a list of the feature that are in JGL but not in STL:
Maps
include an add()
method that takes a key and a value.
Maps
include a put()
method for easily replacing the value associated with a key.
replace()
and remove().
union().
NegativeInteger
.
pushFront()
and popFront().
.
add()
as a synonym for pushBack().
Printing
.
index()
method for obtaining their index.
remove()
,
replace().
atBegin()
and atEnd()
testing methods.
randomShuffle()
works with bidirectional iterators.
sort()
can sort any kind of sequence.
Here is a list of the features that JGL has for compatibility
with existing Java code:
java.util.Enumeration
interface.
Arrays
may be constructed to take ownership of a native array.
java.util.Dictionary
abstract base class.
Array
to avoid a name clash with java.util.Vector
.
HashMap
and HashSet
.
remove()
instead of erase().
OrderedMap
and OrderedSet
.
Here is a list of the differences between JGL and STL that will
probably always remain:
Sets
and Maps
return an Object
from a failed insert()
operation.
getComparitor()
instead of key_comp()
,
value_comp().
public
static
methods of algorithm classes.
pointer_to_function
function objects.
add().
This section contains some code samples that illustrate some of
the similarities and differences between JGL and STL.
STL/C++vector<int> v;
v.push_back( 1 );
v.push_back( 3 );
v.push_back( 2 );
cout << v.front() << ", " << v.back() << endl;
replace( v.begin(), v.end(), 1, 3 );
JGL/JavaArray array = new Array();
array.pushBack( 1 ); // Could use array.add( 1 ) instead.
array.pushBack( 3 );
array.pushBack( 2 );
System.out.println( array.front() + ", " + array.back() );
array.replace( 1, 3 ); // Note that common functions are part of container interface.
STL/C++vector<int> v;
v.push_back( 1 );
v.push_back( 3 );
v.push_back( 2 );
for( vector<int>::iterator i = v.begin(); i != v.end(); i++ )
cout << *I << endl;
JGL/JavaArray array = new Array();
array.pushBack( 1 );
array.pushBack( 3 );
array.pushBack( 2 );
for( ArrayIterator i = array.begin(); !i.equals( array.end() ); i.advance() )
System.out.println( i.get() );
or (clearer and more efficient)
Array array = new Array();
array.pushBack( 1 );
array.pushBack( 3 );
array.pushBack( 2 );
Enumeration e = array.begin();
while( e.hasMoreElements() )
System.out.println( e.nextElement() );
STL/C++int array[] = { 1, 3, 2 };
for( int* p = array; p != array + 3; p++ )
cout << *p << endl;
JGL/Java
int array[] = { 1, 3, 2 };
for( IntIterator p = IntIterator.begin( array ); p.hasMoreElements(); p.advance() )
System.out.println( p.get() );
STL/C++vector<int> v;
v.push_back( 1 );
v.push_back( 3 );
v.push_back( 2 );
sort( v.begin(), v.end() );
JGL/Java
Array array = new Array();
array.pushBack( new Integer( 1 ) );
array.pushBack( new Integer( 3 ) );
array.pushBack( new Integer( 2 ) );
Sorting.sort( array );
STL/C++int array[] = { 1, 3, 2 };
sort( array, array + 3 );
JGL/Java
int ints [] = { 1, 3, 2 };
IntArray array = new IntArray( ints );
Sorting.sort( array );