mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Fix the test to write to a file, in a timed manner.
This commit is contained in:
@@ -23,21 +23,29 @@ import net.openhft.chronicle.map.ChronicleMapBuilder;
|
||||
import net.openhft.lang.model.DataValueClasses;
|
||||
import net.openhft.lang.values.LongValue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class DistributedSequenceMain {
|
||||
|
||||
public static void main(String... ignored) throws IOException {
|
||||
Class<LongValue> longValueClass = DataValueClasses.directClassFor(LongValue.class);
|
||||
File file = File.createTempFile("sequence-numbers", ".dat");
|
||||
try (ChronicleMap<String, LongValue> map =
|
||||
ChronicleMapBuilder.of(String.class, longValueClass)
|
||||
ChronicleMapBuilder.of(String.class, LongValue.class)
|
||||
.entries(128)
|
||||
.actualSegments(1).create()) {
|
||||
LongValue value = DataValueClasses.newDirectReference(longValueClass);
|
||||
map.acquireUsing("sequence", value);
|
||||
.actualSegments(1)
|
||||
.createPersistedTo(file)) {
|
||||
for (int t = 0; t < 5; t++) {
|
||||
LongValue value = DataValueClasses.newDirectReference(LongValue.class);
|
||||
map.acquireUsing("sequence-" + t, value);
|
||||
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
long nextId = value.addAtomicValue(1);
|
||||
long start = System.nanoTime();
|
||||
int runs = 10000000;
|
||||
for (int i = 0; i < runs; i++) {
|
||||
long nextId = value.addAtomicValue(1);
|
||||
}
|
||||
double rate = (double) (System.nanoTime() - start) / runs;
|
||||
System.out.printf("Uncontended increment took an average of %.1f ns.%n", rate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user