54 lines
2.2 KiB
Java
54 lines
2.2 KiB
Java
package org.warp.jcwdb.exampleimpl;
|
|
|
|
import org.warp.jcwdb.EntryReference;
|
|
import org.warp.jcwdb.JCWDatabase;
|
|
import org.warp.jcwdb.LightList;
|
|
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Paths;
|
|
|
|
public class App {
|
|
public static void main(String[] args) throws Exception {
|
|
if (args.length > 2 && Boolean.parseBoolean(args[2])) {
|
|
Files.delete(Paths.get(args[0]));
|
|
Files.delete(Paths.get(args[1]));
|
|
}
|
|
System.out.println("Loading database...");
|
|
long time0 = System.currentTimeMillis();
|
|
JCWDatabase db = new JCWDatabase(Paths.get(args[0]), Paths.get(args[1]));
|
|
long time01 = System.currentTimeMillis();
|
|
System.out.println("Time elapsed: " + (time01 - time0));
|
|
System.out.println("Loading root...");
|
|
LightList<String> root = ((EntryReference<LightList<String>>) db.getRoot().cast()).value;
|
|
long time1 = System.currentTimeMillis();
|
|
System.out.println("Time elapsed: " + (time1 - time01));
|
|
System.out.println("Root:");
|
|
// for (int i = 0; i < root.size(); i++) {
|
|
// System.out.println(" - " + root.get(i));
|
|
// }
|
|
long prectime = System.currentTimeMillis();
|
|
for (int i = 0; i < 2000000/*2000000*/; i++) {
|
|
root.add("Test " + i);
|
|
if (i > 0 && i % 200000 == 0) {
|
|
long precprectime = prectime;
|
|
prectime = System.currentTimeMillis();
|
|
System.out.println("Element "+i + " ("+(prectime-precprectime)+"ms)");
|
|
}
|
|
}
|
|
long time2 = System.currentTimeMillis();
|
|
System.out.println("Root size: "+root.size());
|
|
System.out.println("Time elapsed: " + (time2 - time1));
|
|
System.out.println("Used memory: " + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024) + "MB");
|
|
System.out.println("Cleaning database (to reduce the amount of used memory and detect memory leaks)...");
|
|
long removedItems = db.clean();
|
|
long time3 = System.currentTimeMillis();
|
|
System.out.println("Removed items: " + removedItems);
|
|
System.out.println("Used memory: " + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024) + "MB");
|
|
System.out.println("Time elapsed: " + (time3 - time2));
|
|
System.out.println("Saving database...");
|
|
db.close();
|
|
long time4 = System.currentTimeMillis();
|
|
System.out.println("Time elapsed: " + (time4 - time3));
|
|
}
|
|
}
|