Test use of IntValue

This commit is contained in:
Peter Lawrey
2014-10-01 22:24:03 +01:00
parent 614308f38a
commit a4e6a11d21
2 changed files with 35 additions and 0 deletions
@@ -0,0 +1,35 @@
package net.openhft.chronicle.map.example;
public class WordCount {
static String[] words;
static int expectedSize;
static {
try {
// english version of war and peace -> ascii
String fullText =
new String(Files.readAllBytes(Paths.get("war_and_peace.txt")), UTF_8);
words = fullText.split("\\s+");
expectedSize = (int) Arrays.stream(words).distinct().count();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
static interface ByteableIntValue extends IntValue, Byteable {}
@Benchmark
public int chronicleMap() throws IOException {
ChronicleMap<String, ByteableIntValue> map =
ChronicleMapBuilder.of(String.class, ByteableIntValue.class)
.entrySize(16)
.actualSegments(1)
.entries(expectedSize)
.create();
ByteableIntValue v = map.acquireUsing("a", null);
for (String word : words) {
map.acquireUsing(word, v).addValue(1);
}
return map.acquireUsing("a", v).getValue();
}
}