use of com.cinchapi.concourse.server.plugin.data.LazyTrackingTObjectResultDataset in project concourse by cinchapi.
the class TMapsTest method testTObjectResultDatasetPutPerformance.
@Test
public void testTObjectResultDatasetPutPerformance() throws InterruptedException {
// Constraint: Putting into a Dataset can't be more than an order of
// magnitude slower...
Map<Long, Map<String, Set<TObject>>> spec = Maps.newLinkedHashMap();
int rounds = 1000;
TimeUnit unit = TimeUnit.MICROSECONDS;
for (int i = 0; i < rounds; ++i) {
String key = Random.getSimpleString();
Set<TObject> values = Sets.newLinkedHashSet();
for (int j = 0; j < 10; ++j) {
values.add(Convert.javaToThrift(Random.getObject()));
}
Map<String, Set<TObject>> entry = Maps.newLinkedHashMapWithExpectedSize(1);
entry.put(key, values);
spec.put((long) i, entry);
}
Map<Long, Map<String, Set<TObject>>> map = Maps.newLinkedHashMap();
Map<Long, Map<String, Set<TObject>>> dataset = new LazyTrackingTObjectResultDataset();
Benchmark mapBench = new Benchmark(unit) {
@Override
public void action() {
spec.forEach((record, data) -> {
TMaps.putResultDatasetOptimized(map, record, data);
});
}
};
Benchmark datasetBench = new Benchmark(unit) {
@Override
public void action() {
spec.forEach((record, data) -> {
TMaps.putResultDatasetOptimized(dataset, record, data);
});
}
};
AtomicLong datasetTime = new AtomicLong(0);
AtomicLong mapTime = new AtomicLong(0);
CountDownLatch latch = new CountDownLatch(2);
Thread t1 = new Thread(() -> {
datasetTime.set(datasetBench.run());
latch.countDown();
});
Thread t2 = new Thread(() -> {
mapTime.set(mapBench.run());
latch.countDown();
});
t2.start();
t1.start();
latch.await();
double datasetTimeDigits = Math.ceil(Math.log10(datasetTime.get()));
double mapTimeDigits = Math.ceil(Math.log10(mapTime.get()));
System.out.println(AnyStrings.format("Dataset = {} {} with {} digits", datasetTime.get(), unit, datasetTimeDigits));
System.out.println(AnyStrings.format("Map = {} {} with {} digits", mapTime.get(), unit, mapTimeDigits));
Assert.assertTrue(AnyStrings.format("Datset took {} {} and Map took {} {}", datasetTime.get(), unit, mapTime.get(), unit), datasetTimeDigits - mapTimeDigits <= 1);
}
Aggregations