[Mulgara-svn] r785 - projects/xa2/object-pool/src
andrae at mulgara.org
andrae at mulgara.org
Tue Apr 15 05:15:01 UTC 2008
Author: andrae
Date: 2008-04-14 22:15:00 -0700 (Mon, 14 Apr 2008)
New Revision: 785
Modified:
projects/xa2/object-pool/src/ByteMapTest.java
projects/xa2/object-pool/src/MemoryTrieTest.java
Log:
More tests, specifically in MemoryTrieTest a couple of load/performance tests to start drawing a performance
baseline for future measurements.
Modified: projects/xa2/object-pool/src/ByteMapTest.java
===================================================================
--- projects/xa2/object-pool/src/ByteMapTest.java 2008-04-15 01:46:35 UTC (rev 784)
+++ projects/xa2/object-pool/src/ByteMapTest.java 2008-04-15 05:15:00 UTC (rev 785)
@@ -7,7 +7,10 @@
public class ByteMapTest {
public static void main(String[] args) throws Exception {
testEmpty();
+ testSequentialImmediate();
testSequential();
+ testAlternateImmediate();
+ testAlternate();
}
public static void testEmpty() throws Exception {
@@ -20,6 +23,18 @@
System.out.println("testEmpty Successful");
}
+ public static void testSequentialImmediate() throws Exception {
+ System.out.println("running testSequentialImmediate...");
+ ByteMap<Long> byteMap = new ByteMap<Long>();
+
+ for (int i = 0; i < 0x00000100; i++) {
+ assertTrue("Found double entry for i = " + i + " in sequential map", byteMap.insert((byte)i, new Long(i)));
+ Long l = byteMap.lookup((byte)i);
+ assertEquals("Found mismatching entry for i = " + i + " in sequential map: Received " + l, new Long(i), l);
+ }
+ System.out.println("testSequentialImmediate Successful");
+ }
+
public static void testSequential() throws Exception {
System.out.println("running testSequential...");
ByteMap<Long> byteMap = new ByteMap<Long>();
@@ -27,6 +42,7 @@
for (int i = 0; i < 0x00000100; i++) {
assertTrue("Found double entry for i = " + i + " in sequential map", byteMap.insert((byte)i, new Long(i)));
}
+
for (int i = 0; i < 0x00000100; i++) {
Long l = byteMap.lookup((byte)i);
assertEquals("Found mismatching entry for i = " + i + " in sequential map: Received " + l, new Long(i), l);
@@ -34,6 +50,46 @@
System.out.println("testSequential Successful");
}
+ public static void testAlternateImmediate() throws Exception {
+ System.out.println("running testAlternateImmediate...");
+ ByteMap<Long> byteMap = new ByteMap<Long>();
+
+ for (int i = 0; i < 128; i++) {
+ assertTrue("Found double entry for i = " + i + " in alternate map", byteMap.insert((byte)i, new Long(i)));
+ Long l = byteMap.lookup((byte)i);
+ assertEquals("Found mismatching entry for i = " + i + " in alternate map: Received " + l, new Long(i), l);
+
+ int ii = 255 - i;
+ assertTrue("Found double entry for i' = " + ii + " in alternate map", byteMap.insert((byte)ii, new Long(ii)));
+ Long ll = byteMap.lookup((byte)ii);
+ assertEquals("Found mismatching entry for i' = " + ii + " in alternate map: Received " + ll, new Long(ii), ll);
+ }
+ System.out.println("testAlternateImmediate Successful");
+ }
+
+ public static void testAlternate() throws Exception {
+ System.out.println("running testAlternateImmediate...");
+ ByteMap<Long> byteMap = new ByteMap<Long>();
+
+ for (int i = 0; i < 128; i++) {
+ assertTrue("Found double entry for i = " + i + " in alternate map", byteMap.insert((byte)i, new Long(i)));
+
+ int ii = 255 - i;
+ assertTrue("Found double entry for i' = " + ii + " in alternate map", byteMap.insert((byte)ii, new Long(ii)));
+ }
+
+ for (int i = 0; i < 128; i++) {
+ Long l = byteMap.lookup((byte)i);
+ assertEquals("Found mismatching entry for i = " + i + " in alternate map: Received " + l, new Long(i), l);
+
+ int ii = 255 - i;
+ Long ll = byteMap.lookup((byte)ii);
+ assertEquals("Found mismatching entry for i' = " + ii + " in alternate map: Received " + ll, new Long(ii), ll);
+ }
+
+ System.out.println("testAlternateImmediate Successful");
+ }
+
public static void assertNull(String str, Object obj) throws Exception {
if (obj != null) {
throw new IllegalStateException(str);
Modified: projects/xa2/object-pool/src/MemoryTrieTest.java
===================================================================
--- projects/xa2/object-pool/src/MemoryTrieTest.java 2008-04-15 01:46:35 UTC (rev 784)
+++ projects/xa2/object-pool/src/MemoryTrieTest.java 2008-04-15 05:15:00 UTC (rev 785)
@@ -19,11 +19,12 @@
*/
public class MemoryTrieTest {
public static void main(String[] args) throws Exception {
- testWithFile(new File("../scratch/propernames.uniq"));
- testWithFile(new File("../scratch/connectives.uniq"));
- testWithFile(new File("../scratch/web2a.uniq"));
- testWithFile(new File("../scratch/web2.uniq"));
- testWithRandomFile(new File("/dev/urandom"));
+// testWithFile(new File("../scratch/propernames.uniq"));
+// testWithFile(new File("../scratch/connectives.uniq"));
+// testWithFile(new File("../scratch/web2a.uniq"));
+// testWithFile(new File("../scratch/web2.uniq"));
+// testWithRandomFile(new File("/dev/urandom"));
+ testLoadWithRandomFile(new File("/dev/urandom"));
}
public static void testWithFile(File file) throws Exception {
@@ -34,22 +35,27 @@
BufferedReader names = new BufferedReader(new FileReader(file));
long n = 0;
String name = names.readLine();
+ long _startInsert = System.currentTimeMillis();
while (name != null) {
namesMap.put(name.getBytes(), n);
namesTrie.insert(name.getBytes(), n);
name = names.readLine();
n++;
}
+ long _endInsert = System.currentTimeMillis();
names.close();
System.out.println("Checking lines from " + file);
+ long _startLookup = System.currentTimeMillis();
for (byte[] key : namesMap.keySet()) {
if (namesTrie.lookup(key) != namesMap.get(key)) {
throw new IllegalStateException("Trie doesn't match Map");
}
}
+ long _endLookup = System.currentTimeMillis();
- System.out.println("Test Succeeded with " + file);
+ System.out.println("Test Succeeded with " + file +
+ " insert:" + (_endInsert - _startInsert) + " lookup:" + (_endLookup - _startLookup));
}
public static class Bytes {
@@ -89,6 +95,14 @@
byte[] key;
// Set limit to 0 so initial compact works correctly.
buffer.clear().limit(0);
+ long _startInsert = System.currentTimeMillis();
+ long _aggregateL = 0;
+ long _avlL = 0;
+ long _aggregateS = 0;
+ long _avlS = 0;
+ int nL = 0;
+ int nS = 0;
+
while (n < 5000) {
if (buffer.remaining() < 67*1024 && chan.read(buffer.compact()) == -1) {
break;
@@ -99,14 +113,16 @@
buffer.get(key);
Bytes keyBytes = new Bytes(key);
-// System.err.println("TEST: read - " + keyBytes.hashCode());
-
if (namesMap.containsKey(keyBytes)) {
namesTrie.insert(key, namesMap.get(keyBytes));
} else {
n++;
namesMap.put(keyBytes, n);
+ long _si = System.currentTimeMillis();
namesTrie.insert(key, n);
+ _aggregateL += System.currentTimeMillis() - _si;
+ _avlL += key.length;
+ nL++;
}
for (int i = 0; i < 10; i++) {
@@ -118,19 +134,150 @@
} else {
n++;
namesMap.put(keyBytes, n);
+ long _ss = System.currentTimeMillis();
namesTrie.insert(key, n);
+ _aggregateS += System.currentTimeMillis() - _ss;
+ _avlS += key.length;
+ nS++;
}
}
}
+ long _endInsert = System.currentTimeMillis();
+ System.out.println("Input " + namesMap.size() + " entries");
+ System.out.println(" " + nL + " long entries ave: " + (_avlL / nL) + " in: " + _aggregateL + "ms");
+ System.out.println(" " + nS + " short entries ave: " + (_avlS / nS) + " in: " + _aggregateS + "ms");
chan.close();
+ long _startLookup = System.currentTimeMillis();
System.out.println("Checking random bytes from " + file);
for (Bytes k : namesMap.keySet()) {
if (namesTrie.lookup(k.bytes) != namesMap.get(k)) {
throw new IllegalStateException("Trie doesn't match Map");
}
}
+ long _endLookup = System.currentTimeMillis();
- System.out.println("Test Succeeded with " + file);
+ System.out.println("Test Succeeded with " + file +
+ " insert:" + (_endInsert - _startInsert) + " lookup:" + (_endLookup - _startLookup));
}
+
+ public static void testLoadWithRandomFile(File file) throws Exception {
+ Map<Bytes, Long> namesMap = new HashMap<Bytes, Long>();
+ MemoryTrie namesTrie = new MemoryTrie();
+
+ System.out.println("Inserting random bytes from " + file);
+ FileChannel chan = new FileInputStream(file).getChannel();
+ ByteBuffer buffer = ByteBuffer.allocate(8*1024*1024);
+
+ long n = 0;
+ byte[] key;
+ // Set limit to 0 so initial compact works correctly.
+ buffer.clear().limit(0);
+ long _startInsert = System.currentTimeMillis();
+ long _aggregateL = 0;
+ long _avlL = 0;
+ int nL = 0;
+ long _aggregateLL = 0;
+ long _avlLL = 0;
+ int nLL = 0;
+ long _aggregateS = 0;
+ long _avlS = 0;
+ int nS = 0;
+ long _aggregateSS = 0;
+ long _avlSS = 0;
+ int nSS = 0;
+
+ for (int i = 0; i < 100; i++) {
+ if (buffer.remaining() < 2*1024*1024 && chan.read(buffer.compact()) == -1) {
+ break;
+ }
+ buffer.flip();
+
+ key = new byte[buffer.getInt() & 0x0007FFFF];
+ buffer.get(key);
+ Bytes keyBytes = new Bytes(key);
+
+ if (namesMap.containsKey(keyBytes)) {
+ namesTrie.insert(key, namesMap.get(keyBytes));
+ } else {
+ n++;
+ namesMap.put(keyBytes, n);
+ long _sll = System.currentTimeMillis();
+ namesTrie.insert(key, n);
+ _aggregateLL += System.currentTimeMillis() - _sll;
+ _avlLL += key.length;
+ nLL++;
+ }
+
+ for (int j = 0; j < 10; j++) {
+ key = new byte[((int)buffer.getShort()) & 0x0000FFFF];
+ buffer.get(key);
+ keyBytes = new Bytes(key);
+ if (namesMap.containsKey(keyBytes)) {
+ namesTrie.insert(key, namesMap.get(keyBytes));
+ } else {
+ n++;
+ namesMap.put(keyBytes, n);
+ long _sl = System.currentTimeMillis();
+ namesTrie.insert(key, n);
+ _aggregateL += System.currentTimeMillis() - _sl;
+ _avlL += key.length;
+ nL++;
+ }
+
+ for (int k = 0; k < 10; k++) {
+ key = new byte[((int)buffer.get()) & 0x000000FF];
+ buffer.get(key);
+ keyBytes = new Bytes(key);
+ if (namesMap.containsKey(keyBytes)) {
+ namesTrie.insert(key, namesMap.get(keyBytes));
+ } else {
+ n++;
+ namesMap.put(keyBytes, n);
+ long _ss = System.currentTimeMillis();
+ namesTrie.insert(key, n);
+ _aggregateS += System.currentTimeMillis() - _ss;
+ _avlS += key.length;
+ nS++;
+ }
+
+ for (int ii = 0; ii < 1000; ii++) {
+ key = new byte[((int)buffer.get()) & 0x0000001F];
+ buffer.get(key);
+ keyBytes = new Bytes(key);
+ if (namesMap.containsKey(keyBytes)) {
+ namesTrie.insert(key, namesMap.get(keyBytes));
+ } else {
+ n++;
+ namesMap.put(keyBytes, n);
+ long _sss = System.currentTimeMillis();
+ namesTrie.insert(key, n);
+ _aggregateS += System.currentTimeMillis() - _sss;
+ _avlSS += key.length;
+ nSS++;
+ }
+ }
+ }
+ }
+ }
+ long _endInsert = System.currentTimeMillis();
+ System.out.println("Input " + namesMap.size() + " entries");
+ System.out.println(" " + nLL + " very long entries ave: " + (_avlLL / nLL) + " in: " + _aggregateLL + "ms");
+ System.out.println(" " + nL + " long entries ave: " + (_avlL / nL) + " in: " + _aggregateL + "ms");
+ System.out.println(" " + nS + " short entries ave: " + (_avlS / nS) + " in: " + _aggregateS + "ms");
+ System.out.println(" " + nSS + " very short entries ave: " + (_avlSS / nSS) + " in: " + _aggregateSS + "ms");
+ chan.close();
+
+ long _startLookup = System.currentTimeMillis();
+ System.out.println("Checking random bytes from " + file);
+ for (Bytes k : namesMap.keySet()) {
+ if (namesTrie.lookup(k.bytes) != namesMap.get(k)) {
+ throw new IllegalStateException("Trie doesn't match Map");
+ }
+ }
+ long _endLookup = System.currentTimeMillis();
+
+ System.out.println("Test Succeeded with " + file +
+ " insert:" + (_endInsert - _startInsert) + " lookup:" + (_endLookup - _startLookup));
+ }
}
More information about the Mulgara-svn
mailing list