Search in sources :

Example 1 with LazyTrackingTObjectResultDataset

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);
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject) Set(java.util.Set) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) Benchmark(com.cinchapi.common.profile.Benchmark) TimeUnit(java.util.concurrent.TimeUnit) Map(java.util.Map) LazyTrackingTObjectResultDataset(com.cinchapi.concourse.server.plugin.data.LazyTrackingTObjectResultDataset) Test(org.junit.Test)

Aggregations

Benchmark (com.cinchapi.common.profile.Benchmark)1 LazyTrackingTObjectResultDataset (com.cinchapi.concourse.server.plugin.data.LazyTrackingTObjectResultDataset)1 TObject (com.cinchapi.concourse.thrift.TObject)1 Map (java.util.Map)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Test (org.junit.Test)1