use of com.cinchapi.common.profile.Benchmark in project concourse by cinchapi.
the class ByteableCollectionsTest method testNewVsDeprecatedPerformance.
@Test
public void testNewVsDeprecatedPerformance() throws IOException, InterruptedException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
List<Value> values = Lists.newArrayList();
while (baos.size() < Math.pow(2, 24)) {
Value value = TestData.getValue();
baos.write(ByteBuffers.getByteArray(value.getBytes()));
values.add(value);
}
ByteBuffer bytes = ByteableCollections.toByteBuffer(values);
Path file = Paths.get(TestData.getTemporaryTestFile());
String $file = file.toString();
FileSystem.writeBytes(bytes, $file);
int bufferSize = 8192;
Benchmark benchmark1 = new Benchmark(TimeUnit.MILLISECONDS) {
@Override
public void action() {
CloseableIterator<ByteBuffer> it = ByteableCollections.stream(file, bufferSize);
while (it.hasNext()) {
Value.fromByteBuffer(it.next());
}
it.closeQuietly();
}
};
Benchmark benchmark2 = new Benchmark(TimeUnit.MILLISECONDS) {
@SuppressWarnings("deprecation")
@Override
public void action() {
Iterator<ByteBuffer> it = ByteableCollections.streamingIterator($file, bufferSize);
while (it.hasNext()) {
Value.fromByteBuffer(it.next());
}
}
};
AtomicDouble avg1 = new AtomicDouble();
AtomicDouble avg2 = new AtomicDouble();
CountUpLatch latch = new CountUpLatch();
Thread t1 = new Thread(() -> {
double avg = benchmark1.average(10);
System.out.println("New: " + avg);
avg1.set(avg);
latch.countUp();
});
Thread t2 = new Thread(() -> {
double avg = benchmark2.average(10);
System.out.println("Deprecated: " + avg);
avg2.set(avg);
latch.countUp();
});
List<Thread> threads = Lists.newArrayList(t1, t2);
Collections.shuffle(threads);
for (Thread thread : threads) {
thread.start();
}
latch.await(2);
Assert.assertTrue(avg1.get() < avg2.get());
}
use of com.cinchapi.common.profile.Benchmark in project concourse by cinchapi.
the class StoresTest method testBenchmarkSelectKeysRecordsOptionalAtomicWithNavigation.
@Test
public void testBenchmarkSelectKeysRecordsOptionalAtomicWithNavigation() {
AtomicSupport store = getStore();
setupNavigationGraph(store);
// @formatter:off
List<String> keys = ImmutableList.of("job.title", "job.company.name", "student.name", "student.email", "job.company.website", "association", "foo.bar", "student.association", "job.company.$id$", "student.name.$id$", "job.company");
// @formatter:on
Benchmark serial = new Benchmark(TimeUnit.MICROSECONDS) {
@Override
public void action() {
for (String key : keys) {
Stores.serialSelect(store, key, 1);
}
}
};
Benchmark bulk = new Benchmark(TimeUnit.MICROSECONDS) {
@Override
public void action() {
Stores.select(store, keys, 1);
}
};
double serialTime = serial.average(5);
double bulkTime = bulk.average(5);
System.out.println("multiple navigation serial = " + serialTime);
System.out.println("multiple navigation BULK = " + bulkTime);
}
use of com.cinchapi.common.profile.Benchmark in project concourse by cinchapi.
the class StoresTest method testBenchmarkSelectKeysRecordsOptionalAtomicWithNoNavigation.
@Test
public void testBenchmarkSelectKeysRecordsOptionalAtomicWithNoNavigation() {
AtomicSupport store = getStore();
setupNavigationGraph(store);
// @formatter:off
List<String> keys = ImmutableList.of("job", "student", "association", "foo");
// @formatter:on
Benchmark serial = new Benchmark(TimeUnit.MICROSECONDS) {
@Override
public void action() {
for (String key : keys) {
Stores.serialSelect(store, key, 1);
}
}
};
Benchmark bulk = new Benchmark(TimeUnit.MICROSECONDS) {
@Override
public void action() {
Stores.select(store, keys, 1);
}
};
double serialTime = serial.average(5);
double bulkTime = bulk.average(5);
System.out.println("multiple serial = " + serialTime);
System.out.println("multiple BULK = " + bulkTime);
}
use of com.cinchapi.common.profile.Benchmark in project concourse by cinchapi.
the class StoresTest method testBenchmarkSelectKeyRecordsOptionalAtomicWithNoNavigation.
@Test
public void testBenchmarkSelectKeyRecordsOptionalAtomicWithNoNavigation() {
AtomicSupport store = getStore();
setupNavigationGraph(store);
// @formatter:off
List<String> keys = ImmutableList.of("job");
// @formatter:on
Benchmark serial = new Benchmark(TimeUnit.MICROSECONDS) {
@Override
public void action() {
Stores.serialSelect(store, keys.get(0), 1);
}
};
Benchmark bulk = new Benchmark(TimeUnit.MICROSECONDS) {
@Override
public void action() {
Stores.select(store, keys, 1);
}
};
double serialTime = serial.average(5);
double bulkTime = bulk.average(5);
System.out.println("single serial = " + serialTime);
System.out.println("single BULK = " + bulkTime);
}
use of com.cinchapi.common.profile.Benchmark 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