diff --git a/pom.xml b/pom.xml
index a42e72b..d2fc291 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,7 +35,7 @@
com.h2database
h2-mvstore
- 1.4.200
+ 2.3.232
io.github.microutils
diff --git a/src/main/java/org/lmdbjava/bench/MvStore.java b/src/main/java/org/lmdbjava/bench/MvStore.java
index 493721e..8a90211 100644
--- a/src/main/java/org/lmdbjava/bench/MvStore.java
+++ b/src/main/java/org/lmdbjava/bench/MvStore.java
@@ -2,7 +2,7 @@
* #%L
* LmdbJava Benchmarks
* %%
- * Copyright (C) 2016 - 2022 The LmdbJava Open Source Project
+ * Copyright (C) 2016 - 2024 The LmdbJava Open Source Project
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,12 +31,17 @@
import java.io.File;
import java.io.IOException;
-import java.util.Iterator;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
import org.agrona.MutableDirectBuffer;
import org.agrona.concurrent.UnsafeBuffer;
+import org.h2.mvstore.Cursor;
+import org.h2.mvstore.DataUtils;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;
+import org.h2.mvstore.WriteBuffer;
+import org.h2.mvstore.type.BasicDataType;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
@@ -60,10 +65,10 @@ public class MvStore {
@Benchmark
public void readCrc(final Reader r, final Blackhole bh) {
r.crc.reset();
- final Iterator iter = r.map.keyIterator(null);
- while (iter.hasNext()) {
- final byte[] k = iter.next();
- final byte[] v = r.map.get(k);
+ final Cursor cursor = r.map.cursor(null, null, false);
+ while (cursor.hasNext()) {
+ final byte[] k = cursor.next();
+ final byte[] v = cursor.getValue();
r.crc.update(k);
r.crc.update(v);
}
@@ -78,34 +83,35 @@ public void readKey(final Reader r, final Blackhole bh) {
} else {
r.wkb.putStringWithoutLengthUtf8(0, r.padKey(key));
}
- bh.consume(r.map.get(copyOf(r.wkb.byteArray(), r.keySize)));
+ bh.consume(r.map.get(r.wkb.byteArray()));
}
}
@Benchmark
public void readRev(final Reader r, final Blackhole bh) {
- for (long i = r.map.sizeAsLong() - 1; i >= 0; i--) {
- final byte[] k = r.map.getKey(i);
- bh.consume(r.map.get(k));
+ final Cursor cursor = r.map.cursor(null, null, true);
+ while (cursor.hasNext()) {
+ cursor.next();
+ bh.consume(cursor.getValue());
}
}
@Benchmark
public void readSeq(final Reader r, final Blackhole bh) {
- final Iterator iter = r.map.keyIterator(null);
- while (iter.hasNext()) {
- final byte[] k = iter.next();
- bh.consume(r.map.get(k));
+ final Cursor cursor = r.map.cursor(null, null, false);
+ while (cursor.hasNext()) {
+ cursor.next();
+ bh.consume(cursor.getValue());
}
}
@Benchmark
public void readXxh64(final Reader r, final Blackhole bh) {
long result = 0;
- final Iterator iter = r.map.keyIterator(null);
- while (iter.hasNext()) {
- final byte[] k = iter.next();
- final byte[] v = r.map.get(k);
+ final Cursor cursor = r.map.cursor(null, null, false);
+ while (cursor.hasNext()) {
+ final byte[] k = cursor.next();
+ final byte[] v = cursor.getValue();
result += xx_r39().hashBytes(k);
result += xx_r39().hashBytes(v);
}
@@ -143,7 +149,11 @@ public void setup(final BenchmarkParams b) throws IOException {
.fileName(new File(tmp, "mvstore.db").getAbsolutePath())
.autoCommitDisabled()
.open();
- map = s.openMap("ba2ba");
+ final MVMap.Builder builder = new MVMap.Builder()
+ .keyType(BADataType.INSTANCE)
+ .valueType(BADataType.INSTANCE)
+ .singleWriter();
+ map = s.openMap("ba2ba", builder);
}
@Override
@@ -212,4 +222,38 @@ public void teardown() throws IOException {
}
}
+ public static final class BADataType extends BasicDataType {
+ public static final BADataType INSTANCE = new BADataType();
+
+ private BADataType() { }
+
+ @Override
+ public int getMemory(final byte[] data) {
+ return data.length;
+ }
+
+ @Override
+ public void write(final WriteBuffer buff, final byte[] data) {
+ buff.putVarInt(data.length);
+ buff.put(data);
+ }
+
+ @Override
+ public byte[] read(final ByteBuffer buff) {
+ final int size = DataUtils.readVarInt(buff);
+ final byte[] data = new byte[size];
+ buff.get(data);
+ return data;
+ }
+
+ @Override
+ public byte[][] createStorage(final int size) {
+ return new byte[size][];
+ }
+
+ @Override
+ public int compare(final byte[] one, final byte[] two) {
+ return Arrays.compare(one, two);
+ }
+ }
}