From b34af24e338450377e8ffac14536b4d53dce76bd Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sat, 20 Apr 2019 22:19:07 +0200 Subject: [PATCH] Flush executor --- .../strangedb/tests/Performance.java | 375 ++++++++++-------- strangedb-core | 2 +- 2 files changed, 207 insertions(+), 170 deletions(-) mode change 160000 => 120000 strangedb-core diff --git a/src/test/java/it/cavallium/strangedb/tests/Performance.java b/src/test/java/it/cavallium/strangedb/tests/Performance.java index af2d22a..d32985d 100644 --- a/src/test/java/it/cavallium/strangedb/tests/Performance.java +++ b/src/test/java/it/cavallium/strangedb/tests/Performance.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.Random; public class Performance { - private static boolean FAST_TESTS; + private static int DIVISOR; private static Path rootDirectory; private static Path dbDataFile; @@ -32,6 +32,21 @@ public class Performance { private static Path dbReferencesFile; private static DatabaseJava db; private static boolean tempDirectory; + private static final int BASE_WIDTH = 35; + private static final int SPACE_WIDTH = BASE_WIDTH + 35; + private static String spaces = ""; + private static String bars = ""; + private static boolean doFillTests; + private static boolean doLoadTests; + private static boolean doQueryTests; + private static boolean doInstantiationTests; + + static { + for (int i = 0; i < SPACE_WIDTH; i++) { + spaces += " "; + bars += "-"; + } + } /** * @@ -40,13 +55,27 @@ public class Performance { * @throws InterruptedException */ public static void main(String[] args) throws IOException, InterruptedException { - FAST_TESTS = args.length > 0 && args[0].equalsIgnoreCase("true"); + DIVISOR = args.length > 0 ? Integer.parseInt(args[0]) : 1; if (args.length >= 2) { - rootDirectory = Paths.get(args[1]); - try { + doQueryTests = + args[1].contains("query"); + doFillTests = + args[1].contains("fill"); + doLoadTests = + args[1].contains("load"); + doInstantiationTests = + args[1].contains("new"); + if (args[1].contains("all")) { + doQueryTests = true; + doFillTests = true; + doLoadTests = true; + doInstantiationTests = true; + } + } + if (args.length >= 3) { + rootDirectory = Paths.get(args[2]); + if (Files.notExists(rootDirectory)) { Files.createDirectory(rootDirectory); - } catch (Exception ex) { - } tempDirectory = false; } else { @@ -55,166 +84,176 @@ public class Performance { } generateDb(); System.out.println("Performance test started."); - System.out.println("-------------------------------------------------------+-----------------------------------------------------------------"); - System.out.println("Test name Total Time | Time at 1 Time at 10 Time at 100 Time at 1K Time at 10K"); - System.out.println("-------------------------------------------------------+-----------------------------------------------------------------"); - testS("DatabaseCore creation", 300, Performance::deleteDb, Performance::generateDb, () -> {}); - testS("DatabaseCore root creation", 300, Performance::regenDb, () -> db.loadRoot(PreloadedListContainer::new), () -> {}); + System.out.println(bars + "---------------+-----------------------------------------------------------------"); + System.out.println("Test name" + spaces.substring(0, spaces.length() - 5) + "Total Time | Time at 1 Time at 10 Time at 100 Time at 1K Time at 10K"); + System.out.println(bars + "---------------+-----------------------------------------------------------------"); + if (doInstantiationTests) { + testS("DatabaseCore creation", 300, Performance::deleteDb, Performance::generateDb, () -> {}); + testS("DatabaseCore root creation", 300, Performance::regenDb, () -> db.loadRoot(PreloadedListContainer::new), () -> {}); + } final VariableWrapper preloadedListContainer = new VariableWrapper<>(null); final VariableWrapper simpleEnhancedObjectContainer = new VariableWrapper<>(null); - testS("ObjectStrangeDbList creation", 3000, () -> { - regenDb(); - preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); - }, () -> preloadedListContainer.var.list = new ObjectStrangeDbList<>(db), () -> {}); - testS("ObjectStrangeDbList: Filling with 1000 items", 100, () -> { - regenDb(); - preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); - preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); - }, () -> { - for (int i = 0; i < 1000; i++) { - preloadedListContainer.var.list.add(1000); - } - }, () -> {}); - testS("ObjectStrangeDbList: Filling with 1000 items", 100, () -> { - regenDb(); - preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); - preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrangeDbList<>(db, SimpleEnhancedObject.class); - simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db); - simpleEnhancedObjectContainer.var.integerNumber = 10; - simpleEnhancedObjectContainer.var.longNumber = 10L; - simpleEnhancedObjectContainer.var.object = new ArrayList<>(); - simpleEnhancedObjectContainer.var.object.add("XHIghicuiHUCB UIVY"); - simpleEnhancedObjectContainer.var.object.add("ioZ>UIHZXGHXYGY"); - simpleEnhancedObjectContainer.var.object.add("XJIOUIhcgGuigscwvyv"); - }, () -> { - for (int i = 0; i < 1000; i++) { - preloadedListContainer.var.listOfEnhancedObj.add(simpleEnhancedObjectContainer.var); - } - }, () -> {}); - testS("ObjectStrangeDbList: Filling with 10000 items", 10, () -> { - regenDb(); - preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); - preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); - }, () -> { - for (int i = 0; i < 10000; i++) { - preloadedListContainer.var.list.add(1000); - } - }, () -> {}); - testS("ObjectStrangeDbList: Filling with 100000 items", 1, () -> { - regenDb(); - preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); - preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); - }, () -> { - for (int i = 0; i < 100000; i++) { - preloadedListContainer.var.list.add(1000); - } - }, () -> {}); - testS("ObjectStrangeDbList: Loading 1000 items", 100, () -> { - regenDb(); - preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); - preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); - for (int i = 0; i < 1000; i++) { - preloadedListContainer.var.list.add(1000); - } - }, () -> { - preloadedListContainer.var.list.forEachParallelUnsorted((i) -> {}); - }, () -> {}); - testS("ObjectStrangeDbList: Loading with 1000 items", 100, () -> { - regenDb(); - preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); - preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrangeDbList<>(db, SimpleEnhancedObject.class); - simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db); - simpleEnhancedObjectContainer.var.integerNumber = 10; - simpleEnhancedObjectContainer.var.longNumber = 10L; - simpleEnhancedObjectContainer.var.object = new ArrayList<>(); - simpleEnhancedObjectContainer.var.object.add("XHIghicuiHUCB UIVY"); - simpleEnhancedObjectContainer.var.object.add("ioZ>UIHZXGHXYGY"); - simpleEnhancedObjectContainer.var.object.add("XJIOUIhcgGuigscwvyv"); - for (int i = 0; i < 1000; i++) { - preloadedListContainer.var.listOfEnhancedObj.add(simpleEnhancedObjectContainer.var); - } - }, () -> { - preloadedListContainer.var.listOfEnhancedObj.forEachParallelUnsorted((i) -> {}); - }, () -> {}); - testS("ObjectStrangeDbList: Loading 10000 items", 10, () -> { - regenDb(); - preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); - preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); - for (int i = 0; i < 10000; i++) { - preloadedListContainer.var.list.add(1000); - } - }, () -> { - preloadedListContainer.var.list.forEachParallelUnsorted((i) -> {}); - }, () -> {}); - testS("ObjectStrangeDbList: getLast() with 1000 items", 100, () -> { - regenDb(); - preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); - preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); - for (int i = 0; i < 1000; i++) { - preloadedListContainer.var.list.add(1000); - } - }, () -> { - preloadedListContainer.var.list.getLast(); - }, () -> {}); - testS("ObjectStrangeDbList: getLast() with 1000 items", 100, () -> { - regenDb(); - preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); - preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrangeDbList<>(db, SimpleEnhancedObject.class); - simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db); - simpleEnhancedObjectContainer.var.integerNumber = 10; - simpleEnhancedObjectContainer.var.longNumber = 10L; - simpleEnhancedObjectContainer.var.object = new ArrayList<>(); - simpleEnhancedObjectContainer.var.object.add("XHIghicuiHUCB UIVY"); - simpleEnhancedObjectContainer.var.object.add("ioZ>UIHZXGHXYGY"); - simpleEnhancedObjectContainer.var.object.add("XJIOUIhcgGuigscwvyv"); - for (int i = 0; i < 1000; i++) { - preloadedListContainer.var.listOfEnhancedObj.add(simpleEnhancedObjectContainer.var); - } - }, () -> { - preloadedListContainer.var.listOfEnhancedObj.getLast(); - }, () -> {}); - testS("ObjectStrangeDbList: size() with 1000 items", 100, () -> { - regenDb(); - preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); - preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); - for (int i = 0; i < 1000; i++) { - preloadedListContainer.var.list.add(1000); - } - }, () -> { - preloadedListContainer.var.list.size(); - }, () -> {}); - for (int items = 1000; items <= 100000; items *= 10) { - final int itemsF = items; - testS("ListQuery: query with " + items + " items", 100 / (items / 1000), () -> { + if (doInstantiationTests) { + testS("ObjectStrangeDbList creation", 1000, () -> { regenDb(); preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); - preloadedListContainer.var.listOfMessages = new EnhancedObjectStrangeDbList<>(db); - - Random random = new Random(); - for (int i = 0; i < itemsF; i++) { - EMessageContent content; - if (random.nextBoolean()) { - List stringList = new ArrayList<>(); - for (int j = 0; j < 10; j++) { - stringList.add("[entity]"); - } - byte[] stringBytes = new byte[200]; - random.nextBytes(stringBytes); - content = new EMessageText(db, new EFormattedText(db, new String(stringBytes, StandardCharsets.UTF_8) + (random.nextBoolean() ? "not found" : " text to find!"), stringList.toArray(new String[0]))); - } else { - content = new EMessageOtherContent(db, "EMPTY ABCDEFG"); - } - EMessage message = new EMessage(db, content); - preloadedListContainer.var.listOfMessages.add(message); - } + }, () -> preloadedListContainer.var.list = new ObjectStrangeDbList<>(db), () -> {}); + } + if (doFillTests) { + testS("ObjectStrangeDbList: Filling with 1000 items", 100, () -> { + regenDb(); + preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); + preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); }, () -> { - ListQuery query = ListQuery.create( - ValuePointer.ofField(EMessage.class, "content").field(EMessageText.class, "text").field(EFormattedText.class, "text"), - ContainsIgnoreCase.containsValue("text to find")); - ArrayList results = preloadedListContainer.var.listOfMessages.query(query).asList(); + for (int i = 0; i < 1000; i++) { + preloadedListContainer.var.list.add(1000); + } + }, () -> {}); + testS("ObjectStrangeDbList: Filling with 1000 items", 100, () -> { + regenDb(); + preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); + preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrangeDbList<>(db, SimpleEnhancedObject.class); + simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db); + simpleEnhancedObjectContainer.var.integerNumber = 10; + simpleEnhancedObjectContainer.var.longNumber = 10L; + simpleEnhancedObjectContainer.var.object = new ArrayList<>(); + simpleEnhancedObjectContainer.var.object.add("XHIghicuiHUCB UIVY"); + simpleEnhancedObjectContainer.var.object.add("ioZ>UIHZXGHXYGY"); + simpleEnhancedObjectContainer.var.object.add("XJIOUIhcgGuigscwvyv"); + }, () -> { + for (int i = 0; i < 1000; i++) { + preloadedListContainer.var.listOfEnhancedObj.add(simpleEnhancedObjectContainer.var); + } + }, () -> {}); + testS("ObjectStrangeDbList: Filling with 10000 items", 10, () -> { + regenDb(); + preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); + preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); + }, () -> { + for (int i = 0; i < 10000; i++) { + preloadedListContainer.var.list.add(1000); + } + }, () -> {}); + testS("ObjectStrangeDbList: Filling with 100000 items", 1, () -> { + regenDb(); + preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); + preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); + }, () -> { + for (int i = 0; i < 100000; i++) { + preloadedListContainer.var.list.add(1000); + } }, () -> {}); } - System.out.println("-------------------------------------------------------+-----------------------------------------------------------------"); + if (doLoadTests) { + testS("ObjectStrangeDbList: Loading 1000 items", 100, () -> { + regenDb(); + preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); + preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); + for (int i = 0; i < 1000; i++) { + preloadedListContainer.var.list.add(1000); + } + }, () -> { + preloadedListContainer.var.list.forEachParallelUnsorted((i) -> {}); + }, () -> {}); + testS("ObjectStrangeDbList: Loading with 1000 items", 100, () -> { + regenDb(); + preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); + preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrangeDbList<>(db, SimpleEnhancedObject.class); + simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db); + simpleEnhancedObjectContainer.var.integerNumber = 10; + simpleEnhancedObjectContainer.var.longNumber = 10L; + simpleEnhancedObjectContainer.var.object = new ArrayList<>(); + simpleEnhancedObjectContainer.var.object.add("XHIghicuiHUCB UIVY"); + simpleEnhancedObjectContainer.var.object.add("ioZ>UIHZXGHXYGY"); + simpleEnhancedObjectContainer.var.object.add("XJIOUIhcgGuigscwvyv"); + for (int i = 0; i < 1000; i++) { + preloadedListContainer.var.listOfEnhancedObj.add(simpleEnhancedObjectContainer.var); + } + }, () -> { + preloadedListContainer.var.listOfEnhancedObj.forEachParallelUnsorted((i) -> {}); + }, () -> {}); + testS("ObjectStrangeDbList: Loading 10000 items", 10, () -> { + regenDb(); + preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); + preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); + for (int i = 0; i < 10000; i++) { + preloadedListContainer.var.list.add(1000); + } + }, () -> { + preloadedListContainer.var.list.forEachParallelUnsorted((i) -> {}); + }, () -> {}); + testS("ObjectStrangeDbList: getLast() with 1000 items", 100, () -> { + regenDb(); + preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); + preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); + for (int i = 0; i < 1000; i++) { + preloadedListContainer.var.list.add(1000); + } + }, () -> { + preloadedListContainer.var.list.getLast(); + }, () -> {}); + testS("ObjectStrangeDbList: getLast() with 1000 items", 100, () -> { + regenDb(); + preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); + preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrangeDbList<>(db, SimpleEnhancedObject.class); + simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db); + simpleEnhancedObjectContainer.var.integerNumber = 10; + simpleEnhancedObjectContainer.var.longNumber = 10L; + simpleEnhancedObjectContainer.var.object = new ArrayList<>(); + simpleEnhancedObjectContainer.var.object.add("XHIghicuiHUCB UIVY"); + simpleEnhancedObjectContainer.var.object.add("ioZ>UIHZXGHXYGY"); + simpleEnhancedObjectContainer.var.object.add("XJIOUIhcgGuigscwvyv"); + for (int i = 0; i < 1000; i++) { + preloadedListContainer.var.listOfEnhancedObj.add(simpleEnhancedObjectContainer.var); + } + }, () -> { + preloadedListContainer.var.listOfEnhancedObj.getLast(); + }, () -> {}); + testS("ObjectStrangeDbList: size() with 1000 items", 100, () -> { + regenDb(); + preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); + preloadedListContainer.var.list = new ObjectStrangeDbList<>(db); + for (int i = 0; i < 1000; i++) { + preloadedListContainer.var.list.add(1000); + } + }, () -> { + preloadedListContainer.var.list.size(); + }, () -> {}); + } + if (doQueryTests) { + for (int items = 1000; items <= 100000; items *= 10) { + final int itemsF = items; + testS("ListQuery: query with " + items + " items", 100 / (items / 1000), () -> { + regenDb(); + preloadedListContainer.var = db.loadRoot(PreloadedListContainer::new); + preloadedListContainer.var.listOfMessages = new EnhancedObjectStrangeDbList<>(db); + + Random random = new Random(); + for (int i = 0; i < itemsF; i++) { + EMessageContent content; + if (random.nextBoolean()) { + List stringList = new ArrayList<>(); + for (int j = 0; j < 10; j++) { + stringList.add("[entity]"); + } + byte[] stringBytes = new byte[200]; + random.nextBytes(stringBytes); + content = new EMessageText(db, new EFormattedText(db, new String(stringBytes, StandardCharsets.UTF_8) + (random.nextBoolean() ? "not found" : " text to find!"), stringList.toArray(new String[0]))); + } else { + content = new EMessageOtherContent(db, "EMPTY ABCDEFG"); + } + EMessage message = new EMessage(db, content); + preloadedListContainer.var.listOfMessages.add(message); + } + }, () -> { + ListQuery query = ListQuery.create( + ValuePointer.ofField(EMessage.class, "content").field(EMessageText.class, "text").field(EFormattedText.class, "text"), + ContainsIgnoreCase.containsValue("text to find")); + ArrayList results = preloadedListContainer.var.listOfMessages.query(query).asList(); + }, () -> {}); + } + } + System.out.println(bars + "---------------+-----------------------------------------------------------------"); System.out.println("Performance test finished."); deleteDb(); if (tempDirectory) { @@ -225,21 +264,19 @@ public class Performance { private static void NtestS(String description, int times, RunnableWithIO beforeAction, RunnableWithIO action, RunnableWithIO afterAction) throws IOException, InterruptedException { } - private static void testS(String description, int times, RunnableWithIO beforeAction, RunnableWithIO action, RunnableWithIO afterAction) throws IOException, InterruptedException { - if (FAST_TESTS) { - if (times >= 5) { - times /= 5; - } else if (times >= 2) { - times /= 2; - } + + if (times >= 5 * DIVISOR) { + times /= 5 * DIVISOR; + } else if (times >= 2 * DIVISOR) { + times /= 2 * DIVISOR; } description = description + " time is"; - int spacesCount = 40 - description.length(); + int spacesCount = SPACE_WIDTH - description.length(); int cutAt = 0; if (spacesCount < 0) { - spacesCount = 40 - (description.length() - 40); - cutAt = 40; + spacesCount = SPACE_WIDTH - (description.length() - SPACE_WIDTH); + cutAt = SPACE_WIDTH; } StringBuilder spaces = new StringBuilder(); for (int i = 0; i < spacesCount; i++) { diff --git a/strangedb-core b/strangedb-core deleted file mode 160000 index b425e4c..0000000 --- a/strangedb-core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b425e4c12901dd277f944bcf1b0b0f245d8d23b5 diff --git a/strangedb-core b/strangedb-core new file mode 120000 index 0000000..1d00fcd --- /dev/null +++ b/strangedb-core @@ -0,0 +1 @@ +G:/Progetti/Java/Progetti_IntelliJ_Idea/StrangeDb Core \ No newline at end of file