Search in sources :

Example 1 with DummyPojo

use of org.directmemory.misc.DummyPojo in project DirectMemory by raffaeleguidi.

the class TestCachePlusSerialization method basicBench.

@BenchmarkOptions(benchmarkRounds = 50000, warmupRounds = 0, concurrency = 1)
@Test
public void basicBench() {
    DummyPojo d = new DummyPojo("test-" + rnd.nextInt(100000), 1024 + rnd.nextInt(1024));
    Cache.put(d.name, d);
    DummyPojo d2 = (DummyPojo) Cache.retrieve(d.name);
    assertEquals(d.name, d2.name);
}
Also used : DummyPojo(org.directmemory.misc.DummyPojo) Test(org.junit.Test) BenchmarkOptions(com.carrotsearch.junitbenchmarks.BenchmarkOptions)

Example 2 with DummyPojo

use of org.directmemory.misc.DummyPojo in project DirectMemory by raffaeleguidi.

the class SerializerTest method testSerializer.

private void testSerializer(String name, Serializer serializer, int size, int howMany) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
    logger.info("begin " + serializer.getClass().toString());
    Monitor stopWatch = Monitor.get("serializer." + name + "." + size + "bytes");
    Monitor stopWatch2 = Monitor.get("deserializer." + name + "." + size + "bytes");
    DummyPojo pojo = new DummyPojo("test", size);
    for (int i = 0; i < howMany; i++) {
        long split = stopWatch.start();
        final byte[] array = serializer.serialize(pojo, pojo.getClass());
        stopWatch.stop(split);
        long split2 = stopWatch2.start();
        DummyPojo check = (DummyPojo) serializer.deserialize(array, pojo.getClass());
        stopWatch2.stop(split2);
        assertNotNull("object has not been serialized", check);
        assertEquals(pojo.name, check.name);
    }
    logger.info("end serialize " + serializer.getClass().toString() + "\r\n" + stopWatch.toString());
    logger.info("end deserialize " + serializer.getClass().toString() + "\r\n" + stopWatch2.toString());
}
Also used : DummyPojo(org.directmemory.misc.DummyPojo) Monitor(org.directmemory.measures.Monitor)

Aggregations

DummyPojo (org.directmemory.misc.DummyPojo)2 BenchmarkOptions (com.carrotsearch.junitbenchmarks.BenchmarkOptions)1 Monitor (org.directmemory.measures.Monitor)1 Test (org.junit.Test)1