S
Sierra Bravo
Dear all
I'm adding 80368 words (sorted alphabetically) into different data
structures and then serializing the entire container into a file. The
times that I got are shown below (in millseconds), the first column
being the time taken to populate the container (by reading each word
from the wordlist and adding) and the second, for serializing the
entire object.
The original project was to figure out if restoring from a serialized
container was faster than parsing words into a freshly created
container.
The results are counterintuitive for me--the synchronized (and
supposedly-obsolete) vector beats the non-synchronized hashset by
almost a factor of two for both operations! What gives?
Tree 884 2430
Linkedhash 703 2387
Hash 660 2355
Vector 392 987
Array 381 913
sb
-------------
import java.io.*;
import java.util.*;
public class DictCreate {
String word;
Set<String> set;
long t;
boolean flag = true;
public void create() throws Exception {
int count=0;
t = System.currentTimeMillis();
show("Opening word list");
set = new HashSet<String>();
BufferedReader reader = new BufferedReader(new
FileReader("dict.txt"));
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream("words.ser"));
while (true) {
word = reader.readLine();
if (word == null) break;
set.add(word);
count++;
}
show(""+count+" words added. Beginning serialization...");
out.writeObject(set);
show("List serialized");
out.close();
reader.close();
}
public void show(String s) {
System.err.println(s+"["+(System.currentTimeMillis()-t)+"]");
}
public static void main(String s[]) throws Exception {
DictCreate d = new DictCreate();
d.create();
}
}
I'm adding 80368 words (sorted alphabetically) into different data
structures and then serializing the entire container into a file. The
times that I got are shown below (in millseconds), the first column
being the time taken to populate the container (by reading each word
from the wordlist and adding) and the second, for serializing the
entire object.
The original project was to figure out if restoring from a serialized
container was faster than parsing words into a freshly created
container.
The results are counterintuitive for me--the synchronized (and
supposedly-obsolete) vector beats the non-synchronized hashset by
almost a factor of two for both operations! What gives?
Tree 884 2430
Linkedhash 703 2387
Hash 660 2355
Vector 392 987
Array 381 913
sb
-------------
import java.io.*;
import java.util.*;
public class DictCreate {
String word;
Set<String> set;
long t;
boolean flag = true;
public void create() throws Exception {
int count=0;
t = System.currentTimeMillis();
show("Opening word list");
set = new HashSet<String>();
BufferedReader reader = new BufferedReader(new
FileReader("dict.txt"));
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream("words.ser"));
while (true) {
word = reader.readLine();
if (word == null) break;
set.add(word);
count++;
}
show(""+count+" words added. Beginning serialization...");
out.writeObject(set);
show("List serialized");
out.close();
reader.close();
}
public void show(String s) {
System.err.println(s+"["+(System.currentTimeMillis()-t)+"]");
}
public static void main(String s[]) throws Exception {
DictCreate d = new DictCreate();
d.create();
}
}