Skip to content

Instantly share code, notes, and snippets.

@komamitsu
Last active May 24, 2017 17:03
Show Gist options
  • Save komamitsu/53e37e9166233ae0d50a431dcf4d485e to your computer and use it in GitHub Desktop.
Save komamitsu/53e37e9166233ae0d50a431dcf4d485e to your computer and use it in GitHub Desktop.
public static void main(String[] args)
throws IOException
{
DoubleArrayTrie da = new DoubleArrayTrie();
List<String> lines = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader("/Users/komamitsu/tmp/sorted_uuids"))) {
String line;
while ((line = reader.readLine()) != null) {
lines.add(line);
}
}
long start = System.currentTimeMillis();
da.build(lines);
long end = System.currentTimeMillis();
System.out.println("Build: " + (end - start) + " ms");
start = System.currentTimeMillis();
try (BufferedReader reader = new BufferedReader(new FileReader("/Users/komamitsu/tmp/uuids"))) {
String line;
while ((line = reader.readLine()) != null) {
int result = da.exactMatchSearch(line);
if (result < 0) {
throw new RuntimeException("Not found");
}
else {
// System.out.println("Found");
}
}
}
end = System.currentTimeMillis();
System.out.println("Scan: " + (end - start) + " ms");
}
/*
Using https://github.com/komiya-atsushi/darts-java
Build: 6092 ms
Scan: 753 ms
*/
public class Test
{
public static void main(String[] args)
throws IOException
{
PatriciaTrie patriciaTrie = new PatriciaTrie();
long start = System.currentTimeMillis();
try (BufferedReader reader = new BufferedReader(new FileReader("/Users/komamitsu/tmp/sorted_uuids"))) {
String line;
while ((line = reader.readLine()) != null) {
patriciaTrie.insert(line);
}
}
long end = System.currentTimeMillis();
System.out.println("Build0: " + (end - start) + " ms");
start = System.currentTimeMillis();
DoubleArray da = new DoubleArray(patriciaTrie);
end = System.currentTimeMillis();
System.out.println("Build1: " + (end - start) + " ms");
start = System.currentTimeMillis();
try (BufferedReader reader = new BufferedReader(new FileReader("/Users/komamitsu/tmp/uuids"))) {
String line;
while ((line = reader.readLine()) != null) {
boolean result = da.contains(line);
if (! result) {
throw new RuntimeException("Not found");
}
else {
// System.out.println("Found");
}
}
}
end = System.currentTimeMillis();
System.out.println("Scan: " + (end - start) + " ms");
}
}
/*
https://github.com/takawitter/trie4j
Build0: 1059 ms
Build1: 2461 ms
Scan: 1092 ms
*/
public class TrieHardTest
{
public static void main(String[] args)
throws IOException
{
long start = System.currentTimeMillis();
Trie<String, Object> trie = Tries.forStrings();
try (BufferedReader reader = new BufferedReader(new FileReader("/Users/komamitsu/tmp/sorted_uuids"))) {
String line;
while ((line = reader.readLine()) != null) {
trie.put(line, true);
}
}
long end = System.currentTimeMillis();
System.out.println("Build: " + (end - start) + " ms");
start = System.currentTimeMillis();
try (BufferedReader reader = new BufferedReader(new FileReader("/Users/komamitsu/tmp/uuids"))) {
String line;
while ((line = reader.readLine()) != null) {
boolean result = trie.containsKey(line);
if (!result) {
throw new RuntimeException("Not found");
}
else {
// System.out.println("Found");
}
}
}
end = System.currentTimeMillis();
System.out.println("Scan: " + (end - start) + " ms");
}
}
/*
https://github.com/ClickerMonkey/TrieHard
Build: 1931 ms
Scan: 931 ms
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment