Skip to content

Instantly share code, notes, and snippets.

@mikaelhg
Last active December 16, 2015 14:09
Show Gist options
  • Save mikaelhg/5446346 to your computer and use it in GitHub Desktop.
Save mikaelhg/5446346 to your computer and use it in GitHub Desktop.
Hazelcast vs. Infinispan
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.carrotsearch.junitbenchmarks.BenchmarkRule;
import com.hazelcast.config.Config;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import java.util.Map;
import java.util.UUID;
public class HazelTest {
@Rule
public org.junit.rules.TestRule benchmarkRun = new BenchmarkRule();
private static HazelcastInstance instance;
private static Map<String, String> map;
@BeforeClass
public static void beforeClass() throws Exception {
Config cfg = new Config();
instance = Hazelcast.newHazelcastInstance(cfg);
map = instance.getMap("benchmark");
}
@AfterClass
public static void afterClass() throws Exception {
instance.getLifecycleService().shutdown();
}
@BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds = 100000)
@Test
public void testHazelcast() throws Exception {
map.put(UUID.randomUUID().toString(), UUID.randomUUID().toString());
}
}
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
import com.carrotsearch.junitbenchmarks.BenchmarkRule;
import org.infinispan.manager.DefaultCacheManager;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import java.util.UUID;
public class InfiniTest {
@Rule
public org.junit.rules.TestRule benchmarkRun = new BenchmarkRule();
private static org.infinispan.Cache<String, String> map;
@BeforeClass
public static void beforeClass() throws Exception {
map = new DefaultCacheManager().getCache("benchmark");
}
@AfterClass
public static void afterClass() throws Exception {
map.stop();
}
@BenchmarkOptions(benchmarkRounds = 1000000, warmupRounds = 100000)
@Test
public void testInfinispan() throws Exception {
map.put(UUID.randomUUID().toString(), UUID.randomUUID().toString());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mapbench</groupId>
<artifactId>mapbench</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
<version>5.2.0.Final</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>com.carrotsearch</groupId>
<artifactId>junit-benchmarks</artifactId>
<version>0.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment