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_2_0
\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 enteringjavac *.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 filesjava ArrayBenchmarks
java MapBenchmarks
java 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 for JGL 2.0
-----------------------------
These benchmarks were run on a Toshiba Tecra computer with
48Mb RAM running Windows NT 4.0 and JDK 1.1 final release.
A ratio of less than 1.0 means that JGL ran faster.
ArrayBenchmarks.txt
-------------------
ratio of jglArrayGetting to jdkVectorGetting is 0.97214216
ratio of jglArrayPutting to jdkVectorPutting is 0.91792065
ratio of jglArrayIterating to jdkVectorIterating is 1.2563047
ratio of jglArrayAdding to jdkVectorAdding is 0.6945063
ratio of jglArrayClearing to jdkVectorClearing is 0.0625
ratio of jglArrayInserting to jdkVectorInserting is 1.171401
ratio of jglArrayRemoving to jdkVectorRemoving is 0.9390602
MapBenchmarks.txt
-----------------
ratio of jglMapAdding to jdkHashtableAdding is 1.0936952
ratio of jglMapFinding to jdkHashtableFinding is 1.0753689
ratio of jglMapRemoving to jdkHashtableRemoving is 2.4360888
ratio of jglMapClearing to jdkHashtableClearing is 0.61538464
SortingBenchmarks.txt
---------------------
ratio of jgl sort algorithm to handcoded sorting is 1.7280324
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 features 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().
NegativeNumber
.
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( new Integer( 1 ) ); // Could use array.add( new Integer( 1 ) ) instead.
array.pushBack( new integer( 3 ) );
array.pushBack( new Integer( 2 ) );
System.out.println( array.front() + ", " + array.back() );
array.replace( new Integer( 1 ), new Integer( 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( new Integer( 1 ) );
array.pushBack( new Integer( 3 ) );
array.pushBack( new Integer( 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( new Integer( 1 ) );
array.pushBack( new Integer( 3 ) );
array.pushBack( new Integer( 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 );
There have been several changes and bug fixes since the 1.1 release of JGL. Probably
the biggest change is that it now requires a Java compiler that JDK 1.1
compatible. A full listing of the differences can be found in
changes.txt in the doc directory.