diff --git a/core/pom.xml b/core/pom.xml
index 4c28958d479..bb4939fcb8c 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -253,6 +253,13 @@
1.37
test
+
+
+ org.knowm.xchart
+ xchart
+ 3.8.7
+ test
+
diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/index/nkbtree/normalizers/KeyNormalizerVsSerializerBenchmark.java b/core/src/test/java/com/orientechnologies/orient/core/storage/index/nkbtree/normalizers/KeyNormalizerVsSerializerBenchmark.java
new file mode 100755
index 00000000000..f1ee212a8db
--- /dev/null
+++ b/core/src/test/java/com/orientechnologies/orient/core/storage/index/nkbtree/normalizers/KeyNormalizerVsSerializerBenchmark.java
@@ -0,0 +1,325 @@
+package com.orientechnologies.orient.core.storage.index.nkbtree.normalizers;
+
+import static com.orientechnologies.common.serialization.types.OLongSerializer.LONG_SIZE;
+
+import com.orientechnologies.common.serialization.types.OBinaryTypeSerializer;
+import com.orientechnologies.common.serialization.types.OBooleanSerializer;
+import com.orientechnologies.common.serialization.types.OByteSerializer;
+import com.orientechnologies.common.serialization.types.ODateSerializer;
+import com.orientechnologies.common.serialization.types.ODateTimeSerializer;
+import com.orientechnologies.common.serialization.types.ODecimalSerializer;
+import com.orientechnologies.common.serialization.types.ODoubleSerializer;
+import com.orientechnologies.common.serialization.types.OFloatSerializer;
+import com.orientechnologies.common.serialization.types.OIntegerSerializer;
+import com.orientechnologies.common.serialization.types.OLongSerializer;
+import com.orientechnologies.common.serialization.types.OShortSerializer;
+import com.orientechnologies.common.serialization.types.OStringSerializer;
+import com.orientechnologies.common.serialization.types.OUTF8Serializer;
+import com.orientechnologies.orient.core.storage.index.nkbtree.normalizers.benchmark.Plotter;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.nio.ByteOrder;
+import java.text.Collator;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import org.knowm.xchart.XYChart;
+import org.knowm.xchart.style.Styler;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.profile.StackProfiler;
+import org.openjdk.jmh.results.Result;
+import org.openjdk.jmh.results.RunResult;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+@State(Scope.Thread)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@Measurement(iterations = 1, batchSize = 1)
+@Warmup(iterations = 1, batchSize = 1)
+@Fork(0)
+public class KeyNormalizerVsSerializerBenchmark {
+ private KeyNormalizer keyNormalizer;
+ private ByteOrder byteOrder;
+
+ public static void main(String[] args) throws RunnerException, IOException {
+ final Options opt =
+ new OptionsBuilder()
+ .include("KeyNormalizerVsSerializerBenchmark.*")
+ .addProfiler(StackProfiler.class, "detailLine=true;excludePackages=true;period=1")
+ .jvmArgs("-server", "-XX:+UseConcMarkSweepGC", "-Xmx4G", "-Xms1G")
+ // .result("target" + "/" + "results.csv")
+ // .param("offHeapMessages", "true""
+ // .resultFormat(ResultFormatType.CSV)
+ .build();
+ new KeyNormalizerVsSerializerBenchmark().postProcessRunResult(new Runner(opt).run());
+ }
+
+ private class Pair {
+ private RunResult serializer;
+ private RunResult normalizer;
+
+ public Pair() {}
+
+ public RunResult getSerializer() {
+ return serializer;
+ }
+
+ public void setSerializer(RunResult serializer) {
+ this.serializer = serializer;
+ }
+
+ public RunResult getNormalizer() {
+ return normalizer;
+ }
+
+ public void setNormalizer(RunResult normalizer) {
+ this.normalizer = normalizer;
+ }
+ }
+
+ private void postProcessRunResult(final Collection results) throws IOException {
+ final Map resultMap = buildResultMap(results);
+
+ final Plotter plotter = new Plotter();
+ final XYChart chart =
+ plotter.getXYChart(
+ "Serializer vs. Normalizer",
+ "Test",
+ "Average time (us)",
+ Styler.LegendPosition.InsideNE);
+ final List xData = new ArrayList<>();
+ final List yData = new ArrayList<>();
+
+ final List xDataNormalizer = new ArrayList<>();
+ final List yDataNormalizer = new ArrayList<>();
+
+ int counter = 0;
+ for (final Map.Entry pair : resultMap.entrySet()) {
+ xData.add(counter);
+ if (pair.getValue().getSerializer() != null) {
+ yData.add(pair.getValue().getSerializer().getPrimaryResult().getScore());
+ } else {
+ yData.add(0.0);
+ }
+
+ xDataNormalizer.add(counter);
+ if (pair.getValue().getNormalizer() != null) {
+ yDataNormalizer.add(pair.getValue().getNormalizer().getPrimaryResult().getScore());
+ } else {
+ yDataNormalizer.add(0.0);
+ }
+ counter++;
+ }
+ plotter.addSeriesToLineChart(chart, "Serializer", xData, yData);
+ plotter.addSeriesToLineChart(chart, "Normalizer", xDataNormalizer, yDataNormalizer);
+
+ plotter.exportChartAsPDF(chart, "core/target/normalizerVsSerializer");
+ }
+
+ private Map buildResultMap(Collection results) {
+ final Map map = new HashMap<>();
+ for (final RunResult rr : results) {
+ final Result pr = rr.getPrimaryResult();
+ final String key = pr.getLabel().replaceAll("Normalizer", "").replaceAll("Serializer", "");
+
+ Pair pair = new Pair();
+ if (map.containsKey(key)) {
+ pair = map.get(key);
+ }
+
+ if (pr.getLabel().contains("Normalizer")) {
+ pair.setNormalizer(rr);
+ } else {
+ pair.setSerializer(rr);
+ }
+ map.put(key, pair);
+ }
+ return map;
+ }
+
+ @Setup(Level.Iteration)
+ public void setup() {
+ keyNormalizer = new KeyNormalizer();
+ byteOrder = ByteOrder.nativeOrder();
+ }
+
+ @Benchmark
+ public void booleanSerializer() {
+ final OBooleanSerializer serializer = new OBooleanSerializer();
+ serializer.serialize(true, new byte[1], 0);
+ }
+
+ @Benchmark
+ public void booleanNormalizer() throws Exception {
+ final BooleanKeyNormalizer normalizer = new BooleanKeyNormalizer();
+ normalizer.execute(true, 0);
+ }
+
+ @Benchmark
+ public void byteSerializer() {
+ final OByteSerializer serializer = new OByteSerializer();
+ serializer.serialize((byte) 3, new byte[1], 0);
+ }
+
+ @Benchmark
+ public void byteNormalizer() throws Exception {
+ final ByteKeyNormalizer normalizer = new ByteKeyNormalizer();
+ normalizer.execute((byte) 3, 0);
+ }
+
+ @Benchmark
+ public void integerSerializer() {
+ final OIntegerSerializer serializer = new OIntegerSerializer();
+ serializer.serialize(5, new byte[4], 0);
+ }
+
+ @Benchmark
+ public void integerNormalizer() throws Exception {
+ final IntegerKeyNormalizer normalizer = new IntegerKeyNormalizer();
+ normalizer.execute(5, 0);
+ }
+
+ @Benchmark
+ public void floatSerializer() {
+ final OFloatSerializer serializer = new OFloatSerializer();
+ serializer.serialize(1.5f, new byte[4], 0);
+ }
+
+ @Benchmark
+ public void floatNormalizer() throws Exception {
+ final FloatKeyNormalizer normalizer = new FloatKeyNormalizer();
+ normalizer.execute(1.5f, 0);
+ }
+
+ @Benchmark
+ public void doubleSerializer() {
+ final ODoubleSerializer serializer = new ODoubleSerializer();
+ serializer.serialize(1.5d, new byte[8], 0);
+ }
+
+ @Benchmark
+ public void doubleNormalizer() throws Exception {
+ final DoubleKeyNormalizer normalizer = new DoubleKeyNormalizer();
+ normalizer.execute(1.5d, 0);
+ }
+
+ @Benchmark
+ public void shortSerializer() {
+ final OShortSerializer serializer = new OShortSerializer();
+ serializer.serialize((short) 3, new byte[2], 0);
+ }
+
+ @Benchmark
+ public void shortNormalizer() throws Exception {
+ final ShortKeyNormalizer normalizer = new ShortKeyNormalizer();
+ normalizer.execute((short) 3, 0);
+ }
+
+ @Benchmark
+ public void longSerializer() {
+ final OLongSerializer serializer = new OLongSerializer();
+ serializer.serialize(5L, new byte[LONG_SIZE], 0);
+ }
+
+ @Benchmark
+ public void longNormalizer() throws Exception {
+ final LongKeyNormalizer normalizer = new LongKeyNormalizer();
+ normalizer.execute(5L, 0);
+ }
+
+ @Benchmark
+ public void stringSerializer() {
+ final OStringSerializer serializer = new OStringSerializer();
+ serializer.serialize("abcd", new byte[16], 0);
+ }
+
+ @Benchmark
+ public void stringUtf8Serializer() {
+ final OUTF8Serializer serializer = new OUTF8Serializer();
+ serializer.serialize("abcd", new byte[16], 0);
+ }
+
+ @Benchmark
+ public void stringNormalizer() throws Exception {
+ final StringKeyNormalizer normalizer = new StringKeyNormalizer();
+ normalizer.execute("abcd", Collator.NO_DECOMPOSITION);
+ }
+
+ @Benchmark
+ public void binarySerializer() {
+ final OBinaryTypeSerializer serializer = new OBinaryTypeSerializer();
+ final byte[] binary = new byte[] {1, 2, 3, 4, 5, 6};
+ serializer.serialize(binary, new byte[binary.length + OIntegerSerializer.INT_SIZE], 0);
+ }
+
+ @Benchmark
+ public void binaryNormalizer() throws Exception {
+ final BinaryKeyNormalizer normalizer = new BinaryKeyNormalizer();
+ final byte[] binary = new byte[] {1, 2, 3, 4, 5, 6};
+ normalizer.execute(binary, 0);
+ }
+
+ @Benchmark
+ public void dateSerializer() {
+ final ODateSerializer serializer = new ODateSerializer();
+ final Date date = new GregorianCalendar(2013, Calendar.NOVEMBER, 5).getTime();
+ serializer.serialize(date, new byte[LONG_SIZE], 0);
+ }
+
+ @Benchmark
+ public void dateNormalizer() throws Exception {
+ final DateKeyNormalizer normalizer = new DateKeyNormalizer();
+ final Date date = new GregorianCalendar(2013, Calendar.NOVEMBER, 5).getTime();
+ normalizer.execute(date, 0);
+ }
+
+ @Benchmark
+ public void dateTimeSerializer() {
+ final ODateTimeSerializer serializer = new ODateTimeSerializer();
+ final LocalDateTime ldt = LocalDateTime.of(2013, 11, 5, 3, 3, 3);
+ final Date date = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
+ serializer.serialize(date, new byte[LONG_SIZE], 0);
+ }
+
+ @Benchmark
+ public void dateTimeNormalizer() throws Exception {
+ final DateKeyNormalizer normalizer = new DateKeyNormalizer();
+ final LocalDateTime ldt = LocalDateTime.of(2013, 11, 5, 3, 3, 3);
+ final Date date = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
+ normalizer.execute(date, 0);
+ }
+
+ @Benchmark
+ public void decimalSerializer() {
+ final ODecimalSerializer serializer = new ODecimalSerializer();
+ serializer.serialize(new BigDecimal(new BigInteger("20"), 2), new byte[9], 0);
+ }
+
+ @Benchmark
+ public void decimalNormalizer() throws Exception {
+ final DecimalKeyNormalizer normalizer = new DecimalKeyNormalizer();
+ normalizer.execute(new BigDecimal(new BigInteger("20"), 2), 0);
+ }
+}
diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/index/nkbtree/normalizers/benchmark/LineResultData.java b/core/src/test/java/com/orientechnologies/orient/core/storage/index/nkbtree/normalizers/benchmark/LineResultData.java
new file mode 100755
index 00000000000..0df21aa02e6
--- /dev/null
+++ b/core/src/test/java/com/orientechnologies/orient/core/storage/index/nkbtree/normalizers/benchmark/LineResultData.java
@@ -0,0 +1,33 @@
+package com.orientechnologies.orient.core.storage.index.nkbtree.normalizers.benchmark;
+
+import java.util.List;
+
+public class LineResultData {
+ private String seriesName;
+ private List xData;
+ private List yData;
+
+ public LineResultData(final String seriesName) {
+ this.seriesName = seriesName;
+ }
+
+ public void addXData(final List xData) {
+ this.xData = xData;
+ }
+
+ public void addYData(final List yData) {
+ this.yData = yData;
+ }
+
+ public String getSeriesName() {
+ return this.seriesName;
+ }
+
+ public List getxData() {
+ return xData;
+ }
+
+ public List getyData() {
+ return yData;
+ }
+}
diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/index/nkbtree/normalizers/benchmark/Plotter.java b/core/src/test/java/com/orientechnologies/orient/core/storage/index/nkbtree/normalizers/benchmark/Plotter.java
new file mode 100755
index 00000000000..14fb5001533
--- /dev/null
+++ b/core/src/test/java/com/orientechnologies/orient/core/storage/index/nkbtree/normalizers/benchmark/Plotter.java
@@ -0,0 +1,113 @@
+package com.orientechnologies.orient.core.storage.index.nkbtree.normalizers.benchmark;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import org.knowm.xchart.*;
+import org.knowm.xchart.internal.chartpart.Chart;
+import org.knowm.xchart.style.Styler;
+
+public class Plotter {
+ public CategoryChart getCategoryChart(
+ final String chartName,
+ final String xAxisTitle,
+ final String yAxisTitle,
+ final Styler.LegendPosition position) {
+ final CategoryChart chart =
+ new CategoryChartBuilder()
+ .width(500)
+ .height(500)
+ .title(chartName)
+ .xAxisTitle(xAxisTitle)
+ .theme(Styler.ChartTheme.Matlab)
+ .yAxisTitle(yAxisTitle)
+ .build();
+ chart.getStyler().setLegendPosition(position);
+ chart.getStyler().setAvailableSpaceFill(.96);
+ return chart;
+ }
+
+ public XYChart getXYChart(
+ final String chartName,
+ final String xAxisTitle,
+ final String yAxisTitle,
+ final Styler.LegendPosition position) {
+ final XYChart chart =
+ new XYChartBuilder()
+ .width(500)
+ .height(500) // .title(chartName)
+ .theme(Styler.ChartTheme.Matlab)
+ .xAxisTitle(xAxisTitle)
+ .yAxisTitle(yAxisTitle)
+ .build();
+ chart.getStyler().setChartTitleVisible(true);
+ chart.getStyler().setLegendPosition(position);
+ chart.getStyler().setYAxisLogarithmic(false);
+ chart.getStyler().setDefaultSeriesRenderStyle(XYSeries.XYSeriesRenderStyle.Line);
+ chart.getStyler().setXAxisLabelRotation(45);
+ return chart;
+ }
+
+ public Histogram addSeriesToHistogram(final CategoryChart chart) {
+ Histogram histogram = new Histogram(getGaussianData(10000), 10, -10, 10);
+ chart.addSeries(
+ "histogram",
+ histogram.getxAxisData(),
+ histogram.getyAxisData(),
+ getFakeErrorData(histogram.getxAxisData().size()));
+ return histogram;
+ }
+
+ public Histogram addSeriesToHistogram(final CategoryChart chart, final List data) {
+ Histogram histogram = new Histogram(data, 10, -10, 10);
+ chart.addSeries("histogram", histogram.getxAxisData(), histogram.getyAxisData());
+ return histogram;
+ }
+
+ public Histogram addSeriesToHistogram(
+ final CategoryChart chart, final List data, final List errorData) {
+ Histogram histogram = new Histogram(data, 10, -10, 10);
+ chart.addSeries("histogram", histogram.getxAxisData(), histogram.getyAxisData(), errorData);
+ return histogram;
+ }
+
+ public XYChart addSeriesToLineChart(
+ final XYChart chart, final String seriesName, final List xData, final List yData) {
+ chart.addSeries(seriesName, xData, yData);
+ return chart;
+ }
+
+ public void addSeriesToLineChart(final XYChart chart, final List seriesData) {
+ for (final LineResultData lrd : seriesData) {
+ this.addSeriesToLineChart(chart, lrd.getSeriesName(), lrd.getxData(), lrd.getyData());
+ }
+ }
+
+ private List getGaussianData(int count) {
+ List data = new ArrayList(count);
+ Random r = new Random();
+ for (int i = 0; i < count; i++) {
+ data.add(r.nextGaussian() * 5);
+ }
+ return data;
+ }
+
+ private List getFakeErrorData(int count) {
+ final List data = new ArrayList(count);
+ Random r = new Random();
+ for (int i = 0; i < count; i++) {
+ data.add(r.nextDouble() * 200);
+ }
+ return data;
+ }
+
+ public void exportChartAsPDF(final Chart chart, final String fileName) throws IOException {
+ VectorGraphicsEncoder.saveVectorGraphic(
+ chart, fileName, VectorGraphicsEncoder.VectorGraphicsFormat.PDF);
+ }
+
+ public void exportChartAsPNG(final Chart chart, final String fileName) throws IOException {
+ BitmapEncoder.saveBitmap(chart, fileName, BitmapEncoder.BitmapFormat.PNG);
+ }
+}
diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/index/nkbtree/normalizers/benchmark/PlotterTest.java b/core/src/test/java/com/orientechnologies/orient/core/storage/index/nkbtree/normalizers/benchmark/PlotterTest.java
new file mode 100755
index 00000000000..a90fa61c369
--- /dev/null
+++ b/core/src/test/java/com/orientechnologies/orient/core/storage/index/nkbtree/normalizers/benchmark/PlotterTest.java
@@ -0,0 +1,46 @@
+package com.orientechnologies.orient.core.storage.index.nkbtree.normalizers.benchmark;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.knowm.xchart.CategoryChart;
+import org.knowm.xchart.XYChart;
+import org.knowm.xchart.style.Styler;
+
+public class PlotterTest {
+ private Plotter plotter;
+
+ @Before
+ public void setup() {
+ plotter = new Plotter();
+ }
+
+ @Test
+ public void histogram() throws Exception {
+ final CategoryChart chart =
+ plotter.getCategoryChart(
+ "Test chart name", "Test x axis", "Test y axis", Styler.LegendPosition.InsideNW);
+ plotter.addSeriesToHistogram(chart);
+ plotter.exportChartAsPDF(chart, "target/histogram");
+ Assert.assertTrue(new File("target/histogram.pdf").exists());
+ }
+
+ @Test
+ public void lineChart() throws Exception {
+ final XYChart chart =
+ plotter.getXYChart(
+ "Test chart name", "Test x axis", "Test y axis", Styler.LegendPosition.InsideNW);
+ final List xData = new ArrayList<>();
+ final List yData = new ArrayList<>();
+ for (int i = -3; i <= 3; i++) {
+ xData.add(i);
+ yData.add(Math.pow(10, i));
+ }
+ plotter.addSeriesToLineChart(chart, "10^x", xData, yData);
+ plotter.exportChartAsPDF(chart, "target/lineChart");
+ Assert.assertTrue(new File("target/lineChart.pdf").exists());
+ }
+}
diff --git a/tests/pom.xml b/tests/pom.xml
index e52a8056772..32d6cec1e93 100644
--- a/tests/pom.xml
+++ b/tests/pom.xml
@@ -126,6 +126,13 @@
test
+
+
+ org.knowm.xchart
+ xchart
+ 3.8.5
+ test
+
diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/JSONTestBenchmark.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/JSONTestBenchmark.java
index 1fa119aa576..af126349c36 100755
--- a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/JSONTestBenchmark.java
+++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/JSONTestBenchmark.java
@@ -16,19 +16,20 @@
package com.orientechnologies.orient.test.database.auto;
import com.orientechnologies.orient.core.record.impl.ODocument;
+import com.orientechnologies.orient.core.storage.index.nkbtree.normalizers.benchmark.Plotter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
import java.util.concurrent.TimeUnit;
-import org.openjdk.jmh.annotations.Benchmark;
-import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.Fork;
-import org.openjdk.jmh.annotations.Measurement;
-import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.annotations.OutputTimeUnit;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.State;
-import org.openjdk.jmh.annotations.Warmup;
+import org.knowm.xchart.XYChart;
+import org.knowm.xchart.style.Styler;
+import org.openjdk.jmh.annotations.*;
+import org.openjdk.jmh.results.Result;
+import org.openjdk.jmh.results.RunResult;
+import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
@@ -51,9 +52,38 @@ public static void main(String[] args) throws RunnerException, IOException {
// .param("offHeapMessages", "true""
// .resultFormat(ResultFormatType.CSV)
.build();
+ postProcessRunResult(new Runner(opt).run());
return;
}
+ private static void postProcessRunResult(final Collection results) throws IOException {
+ final Plotter plotter = new Plotter();
+ final XYChart chart =
+ plotter.getXYChart(
+ "String vs. Stream", "Test", "Average time (us)", Styler.LegendPosition.InsideNW);
+ final List xData = new ArrayList<>();
+ final List yData = new ArrayList<>();
+
+ final List xDataStream = new ArrayList<>();
+ final List yDataStream = new ArrayList<>();
+ for (int i = 0; i < results.size(); i++) {
+ final RunResult runResult = (RunResult) results.toArray()[i];
+ final Result result = runResult.getPrimaryResult();
+ final double score = result.getScore();
+ if (!result.getLabel().contains("Stream")) {
+ xData.add(i);
+ yData.add(score);
+ } else {
+ xDataStream.add(i - 1);
+ yDataStream.add(score);
+ }
+ }
+ plotter.addSeriesToLineChart(chart, "String", xData, yData);
+ plotter.addSeriesToLineChart(chart, "Stream", xDataStream, yDataStream);
+
+ plotter.exportChartAsPDF(chart, "tests/target/stringVsStreamParsing");
+ }
+
@Benchmark
public void testAlmostLink() {
final ODocument doc = new ODocument();
diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/benchmark/LineResultData.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/benchmark/LineResultData.java
new file mode 100755
index 00000000000..e7471e559d4
--- /dev/null
+++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/benchmark/LineResultData.java
@@ -0,0 +1,33 @@
+package com.orientechnologies.orient.test.database.auto.benchmark;
+
+import java.util.List;
+
+public class LineResultData {
+ private String seriesName;
+ private List xData;
+ private List yData;
+
+ public LineResultData(final String seriesName) {
+ this.seriesName = seriesName;
+ }
+
+ public void addXData(final List xData) {
+ this.xData = xData;
+ }
+
+ public void addYData(final List yData) {
+ this.yData = yData;
+ }
+
+ public String getSeriesName() {
+ return this.seriesName;
+ }
+
+ public List getxData() {
+ return xData;
+ }
+
+ public List getyData() {
+ return yData;
+ }
+}
diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/benchmark/Plotter.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/benchmark/Plotter.java
new file mode 100755
index 00000000000..71bf5517071
--- /dev/null
+++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/benchmark/Plotter.java
@@ -0,0 +1,113 @@
+package com.orientechnologies.orient.test.database.auto.benchmark;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import org.knowm.xchart.*;
+import org.knowm.xchart.internal.chartpart.Chart;
+import org.knowm.xchart.style.Styler;
+
+public class Plotter {
+ public CategoryChart getCategoryChart(
+ final String chartName,
+ final String xAxisTitle,
+ final String yAxisTitle,
+ final Styler.LegendPosition position) {
+ final CategoryChart chart =
+ new CategoryChartBuilder()
+ .width(500)
+ .height(500)
+ .title(chartName)
+ .xAxisTitle(xAxisTitle)
+ .theme(Styler.ChartTheme.Matlab)
+ .yAxisTitle(yAxisTitle)
+ .build();
+ chart.getStyler().setLegendPosition(position);
+ chart.getStyler().setAvailableSpaceFill(.96);
+ return chart;
+ }
+
+ public XYChart getXYChart(
+ final String chartName,
+ final String xAxisTitle,
+ final String yAxisTitle,
+ final Styler.LegendPosition position) {
+ final XYChart chart =
+ new XYChartBuilder()
+ .width(500)
+ .height(500) // .title(chartName)
+ .theme(Styler.ChartTheme.Matlab)
+ .xAxisTitle(xAxisTitle)
+ .yAxisTitle(yAxisTitle)
+ .build();
+ chart.getStyler().setChartTitleVisible(true);
+ chart.getStyler().setLegendPosition(position);
+ chart.getStyler().setYAxisLogarithmic(false);
+ chart.getStyler().setDefaultSeriesRenderStyle(XYSeries.XYSeriesRenderStyle.Line);
+ chart.getStyler().setXAxisLabelRotation(45);
+ return chart;
+ }
+
+ public Histogram addSeriesToHistogram(final CategoryChart chart) {
+ Histogram histogram = new Histogram(getGaussianData(10000), 10, -10, 10);
+ chart.addSeries(
+ "histogram",
+ histogram.getxAxisData(),
+ histogram.getyAxisData(),
+ getFakeErrorData(histogram.getxAxisData().size()));
+ return histogram;
+ }
+
+ public Histogram addSeriesToHistogram(final CategoryChart chart, final List data) {
+ Histogram histogram = new Histogram(data, 10, -10, 10);
+ chart.addSeries("histogram", histogram.getxAxisData(), histogram.getyAxisData());
+ return histogram;
+ }
+
+ public Histogram addSeriesToHistogram(
+ final CategoryChart chart, final List data, final List errorData) {
+ Histogram histogram = new Histogram(data, 10, -10, 10);
+ chart.addSeries("histogram", histogram.getxAxisData(), histogram.getyAxisData(), errorData);
+ return histogram;
+ }
+
+ public XYChart addSeriesToLineChart(
+ final XYChart chart, final String seriesName, final List xData, final List yData) {
+ chart.addSeries(seriesName, xData, yData);
+ return chart;
+ }
+
+ public void addSeriesToLineChart(final XYChart chart, final List seriesData) {
+ for (final LineResultData lrd : seriesData) {
+ this.addSeriesToLineChart(chart, lrd.getSeriesName(), lrd.getxData(), lrd.getyData());
+ }
+ }
+
+ private List getGaussianData(int count) {
+ List data = new ArrayList(count);
+ Random r = new Random();
+ for (int i = 0; i < count; i++) {
+ data.add(r.nextGaussian() * 5);
+ }
+ return data;
+ }
+
+ private List getFakeErrorData(int count) {
+ final List data = new ArrayList(count);
+ Random r = new Random();
+ for (int i = 0; i < count; i++) {
+ data.add(r.nextDouble() * 200);
+ }
+ return data;
+ }
+
+ public void exportChartAsPDF(final Chart chart, final String fileName) throws IOException {
+ VectorGraphicsEncoder.saveVectorGraphic(
+ chart, fileName, VectorGraphicsEncoder.VectorGraphicsFormat.PDF);
+ }
+
+ public void exportChartAsPNG(final Chart chart, final String fileName) throws IOException {
+ BitmapEncoder.saveBitmap(chart, fileName, BitmapEncoder.BitmapFormat.PNG);
+ }
+}
diff --git a/tests/src/test/java/com/orientechnologies/orient/test/database/auto/benchmark/PlotterTest.java b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/benchmark/PlotterTest.java
new file mode 100755
index 00000000000..84b59e57498
--- /dev/null
+++ b/tests/src/test/java/com/orientechnologies/orient/test/database/auto/benchmark/PlotterTest.java
@@ -0,0 +1,46 @@
+package com.orientechnologies.orient.test.database.auto.benchmark;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.knowm.xchart.CategoryChart;
+import org.knowm.xchart.XYChart;
+import org.knowm.xchart.style.Styler;
+
+public class PlotterTest {
+ private Plotter plotter;
+
+ @Before
+ public void setup() {
+ plotter = new Plotter();
+ }
+
+ @Test
+ public void histogram() throws Exception {
+ final CategoryChart chart =
+ plotter.getCategoryChart(
+ "Test chart name", "Test x axis", "Test y axis", Styler.LegendPosition.InsideNW);
+ plotter.addSeriesToHistogram(chart);
+ plotter.exportChartAsPDF(chart, "target/histogram");
+ Assert.assertTrue(new File("target/histogram.pdf").exists());
+ }
+
+ @Test
+ public void lineChart() throws Exception {
+ final XYChart chart =
+ plotter.getXYChart(
+ "Test chart name", "Test x axis", "Test y axis", Styler.LegendPosition.InsideNW);
+ final List xData = new ArrayList<>();
+ final List yData = new ArrayList<>();
+ for (int i = -3; i <= 3; i++) {
+ xData.add(i);
+ yData.add(Math.pow(10, i));
+ }
+ plotter.addSeriesToLineChart(chart, "10^x", xData, yData);
+ plotter.exportChartAsPDF(chart, "target/lineChart");
+ Assert.assertTrue(new File("target/lineChart.pdf").exists());
+ }
+}