Search in sources :

Example 1 with STRING

use of oap.tree.Dimension.STRING in project oap by oaplatform.

the class TreePerformance method run.

public void run(double fillFactor, int arrayToTree, int dataCount) {
    val bids = new ArrayList<ArrayList<Object>>();
    val dimensions = new ArrayList<Dimension>();
    addStringDimension(dimensions, 20, Dimension.OperationType.CONTAINS);
    addLongDimension(dimensions, 5);
    addStringDimension(dimensions, 30, NOT_CONTAINS);
    addBooleanDimension(dimensions, 10, Dimension.OperationType.CONTAINS);
    addBooleanDimension(dimensions, 10, NOT_CONTAINS);
    addEnumDimension(dimensions, TestEnum1.class, TestEnum1.UNKNOWN1);
    addEnumDimension(dimensions, TestEnum2.class, TestEnum2.Test21);
    addArrayEnumDimension(dimensions, TestEnum3.class, TestEnum3.Test31, 2);
    addArrayStringDimension(dimensions, 5, 300);
    addArrayStringDimension(dimensions, 5, 3);
    addArrayStringDimension(dimensions, 5, 4);
    addArrayStringDimension(dimensions, 5, 5);
    addArrayLongDimension(dimensions, 5, 4);
    addArrayLongDimension(dimensions, 5, 10);
    val data = new ArrayList<Tree.ValueData<String>>();
    fill(dimensions, data, dataCount);
    generateRequests(100, dimensions, bids, data);
    final Tree<String> tree = Tree.<String>tree(dimensions).withHashFillFactor(fillFactor).withArrayToTree(arrayToTree).load(data);
    benchmark("tree-" + fillFactor + "-" + dataCount, SAMPLES, (i) -> {
        Assertions.assertThat(tree.find(bids.get(i % bids.size()))).isNotEmpty();
    }).run();
    System.out.println(tree.getMaxDepth());
}
Also used : lombok.val(lombok.val) RandomUtils(org.apache.commons.lang3.RandomUtils) SneakyThrows(lombok.SneakyThrows) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) STRING(oap.tree.Dimension.STRING) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Matcher(java.util.regex.Matcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Lists(oap.util.Lists) Arrays.asList(java.util.Arrays.asList) Assertions(org.assertj.core.api.Assertions) LONG(oap.tree.Dimension.LONG) ENUM(oap.tree.Dimension.ENUM) BOOLEAN(oap.tree.Dimension.BOOLEAN) lombok.val(lombok.val) Set(java.util.Set) NOT_CONTAINS(oap.tree.Dimension.OperationType.NOT_CONTAINS) AbstractPerformance(oap.testng.AbstractPerformance) List(java.util.List) ARRAY_LONG(oap.tree.Dimension.ARRAY_LONG) ARRAY_STRING(oap.tree.Dimension.ARRAY_STRING) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) ARRAY_ENUM(oap.tree.Dimension.ARRAY_ENUM) Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList)

Example 2 with STRING

use of oap.tree.Dimension.STRING in project oap by oaplatform.

the class TreePerformance method fill.

@SneakyThrows
private void fill(ArrayList<Dimension> dimensions, ArrayList<Tree.ValueData<String>> data, int count) {
    val map = new HashMap<String, ArrayList<String>>();
    val mapSize = new HashMap<String, Integer>();
    val enums = new HashMap<String, ArrayList<Enum<?>>>();
    for (int i = 0; i < count; i++) {
        val selection = new ArrayList<Object>();
        for (Dimension dimension : dimensions) {
            if (dimension.name.startsWith("string")) {
                val list = map.computeIfAbsent(dimension.name, (dn) -> new ArrayList<>());
                if (list.isEmpty()) {
                    for (int r = 0; r < 100; r++) {
                        list.add(RandomStringUtils.randomAlphabetic(10) + i);
                    }
                }
                selection.add(Lists.random(list).get());
            } else if (dimension.name.startsWith("long")) {
                selection.add(RandomUtils.nextLong(0, 1000000));
            } else if (dimension.name.startsWith("boolean")) {
                selection.add(RandomUtils.nextBoolean());
            } else if (dimension.name.startsWith("arrayString")) {
                val size = mapSize.computeIfAbsent(dimension.name, ss -> {
                    final Matcher matcher = ARRAY_STRING_PATTERN.matcher(dimension.name);
                    assert matcher.find();
                    return Integer.parseInt(matcher.group(1));
                });
                val list = map.computeIfAbsent(dimension.name, (dn) -> new ArrayList<>());
                if (list.isEmpty()) {
                    for (int r = 0; r < 100; r++) {
                        list.add(RandomStringUtils.randomAlphabetic(10) + i);
                    }
                }
                val array = new ArrayList<String>();
                for (int s = 0; s < size; s++) {
                    array.add(Lists.random(list).get());
                }
                selection.add(new Tree.Array(array, true));
            } else if (dimension.name.startsWith("arrayEnum")) {
                val size = mapSize.computeIfAbsent(dimension.name, ss1 -> {
                    final Matcher matcher = ARRAY_ENUM_PATTERN.matcher(dimension.name);
                    assert matcher.find();
                    return Integer.parseInt(matcher.group(1));
                });
                val list = enums.computeIfAbsent(dimension.name, (dn) -> new ArrayList<>());
                if (list.isEmpty()) {
                    final Matcher matcher = ARRAY_ENUM_PATTERN.matcher(dimension.name);
                    assert matcher.find();
                    final Class<Enum<?>> clazz = (Class<Enum<?>>) Class.forName(matcher.group(2));
                    final Enum<?>[] enumConstants = clazz.getEnumConstants();
                    list.addAll(asList(enumConstants));
                }
                val array = new ArrayList<Enum<?>>();
                for (int s = 0; s < size; s++) {
                    array.add(Lists.random(list).get());
                }
                selection.add(new Tree.Array(array, true));
            } else if (dimension.name.startsWith("arrayLong")) {
                val array = new ArrayList<Long>();
                val size = mapSize.computeIfAbsent(dimension.name, ss1 -> {
                    final Matcher matcher = ARRAY_LONG_PATTERN.matcher(dimension.name);
                    matcher.find();
                    return Integer.parseInt(matcher.group(1));
                });
                for (int s = 0; s < size; s++) {
                    array.add(RandomUtils.nextLong(0, size));
                }
                selection.add(new Tree.Array(array, true));
            } else if (dimension.name.startsWith("enum")) {
                val list = enums.computeIfAbsent(dimension.name, (dn) -> new ArrayList<>());
                if (list.isEmpty()) {
                    final Matcher matcher = ENUM_PATTERN.matcher(dimension.name);
                    assert matcher.find();
                    final Class<Enum<?>> clazz = (Class<Enum<?>>) Class.forName(matcher.group(1));
                    final Enum<?>[] enumConstants = clazz.getEnumConstants();
                    list.addAll(asList(enumConstants));
                }
                selection.add(Lists.random(list).get());
            } else {
                throw new IllegalStateException("Unknown dimension type " + dimension.name);
            }
        }
        data.add(new Tree.ValueData<>(selection, "data" + i));
    }
}
Also used : lombok.val(lombok.val) RandomUtils(org.apache.commons.lang3.RandomUtils) SneakyThrows(lombok.SneakyThrows) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) STRING(oap.tree.Dimension.STRING) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Matcher(java.util.regex.Matcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Lists(oap.util.Lists) Arrays.asList(java.util.Arrays.asList) Assertions(org.assertj.core.api.Assertions) LONG(oap.tree.Dimension.LONG) ENUM(oap.tree.Dimension.ENUM) BOOLEAN(oap.tree.Dimension.BOOLEAN) lombok.val(lombok.val) Set(java.util.Set) NOT_CONTAINS(oap.tree.Dimension.OperationType.NOT_CONTAINS) AbstractPerformance(oap.testng.AbstractPerformance) List(java.util.List) ARRAY_LONG(oap.tree.Dimension.ARRAY_LONG) ARRAY_STRING(oap.tree.Dimension.ARRAY_STRING) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) ARRAY_ENUM(oap.tree.Dimension.ARRAY_ENUM) Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) SneakyThrows(lombok.SneakyThrows)

Aggregations

ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 SneakyThrows (lombok.SneakyThrows)2 lombok.val (lombok.val)2 AbstractPerformance (oap.testng.AbstractPerformance)2 ARRAY_ENUM (oap.tree.Dimension.ARRAY_ENUM)2 ARRAY_LONG (oap.tree.Dimension.ARRAY_LONG)2 ARRAY_STRING (oap.tree.Dimension.ARRAY_STRING)2 BOOLEAN (oap.tree.Dimension.BOOLEAN)2 ENUM (oap.tree.Dimension.ENUM)2 LONG (oap.tree.Dimension.LONG)2 NOT_CONTAINS (oap.tree.Dimension.OperationType.NOT_CONTAINS)2 STRING (oap.tree.Dimension.STRING)2