Skip to content

This benchmark say nothing #1

Description

@zutherb

i did the benchmark in native java and hazelcast is not so bad. i think jruby distort the benchmark.

import com.hazelcast.config.Config;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import org.apache.commons.lang.time.StopWatch;
import org.infinispan.manager.DefaultCacheManager;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**

  • @author zutherb
    */
    public class PerformanceTest {

    private static final int SIZE = 100000;

    private static final Map<Integer, Integer> JAVA_MAP = new HashMap<Integer, Integer>();
    private static final HazelcastInstance HAZELCAST_INSTANCE;
    private static final DefaultCacheManager INFINISPAN_INSTANCE = new DefaultCacheManager();

    static {
    Config config = new Config();
    Properties properties = new Properties();
    config.setProperties(properties);
    HAZELCAST_INSTANCE = Hazelcast.newHazelcastInstance(config);
    }

    public static void main(String [] args){
    System.out.println("Performance of Java-Map");
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    new Runnable() {
    @OverRide
    protected void doSomething(int i) {
    JAVA_MAP.put(i, i);
    }
    }.run();
    stopWatch.stop();
    System.out.println("write:\t" + stopWatch.toString());

    stopWatch = new StopWatch();
    stopWatch.start();
    new Runnable() {
        @Override
        protected void doSomething(int i) {
            JAVA_MAP.get(i);
        }
    }.run();
    stopWatch.stop();
    System.out.println("read:\t" + stopWatch.toString());
    
    System.out.println("Performance of Hazelcast-Map");
    stopWatch = new StopWatch();
    stopWatch.start();
    new Runnable() {
        @Override
        protected void doSomething(int i) {
            HAZELCAST_INSTANCE.getMap("performance").put(i, i);
        }
    }.run();
    stopWatch.stop();
    System.out.println("write:\t" + stopWatch.toString());
    
    stopWatch = new StopWatch();
    stopWatch.start();
    new Runnable() {
        @Override
        protected void doSomething(int i) {
            HAZELCAST_INSTANCE.getMap("performance").get(i);
        }
    }.run();
    stopWatch.stop();
    System.out.println("read:\t" + stopWatch.toString());
    
    System.out.println("Performance of Hazelcast-Map");
    stopWatch = new StopWatch();
    stopWatch.start();
    new Runnable() {
        @Override
        protected void doSomething(int i) {
            INFINISPAN_INSTANCE.getCache().put(i, i);
        }
    }.run();
    stopWatch.stop();
    System.out.println("write:\t" + stopWatch.toString());
    
    stopWatch = new StopWatch();
    stopWatch.start();
    new Runnable() {
        @Override
        protected void doSomething(int i) {
            INFINISPAN_INSTANCE.getCache().get(i);
        }
    }.run();
    stopWatch.stop();
    System.out.println("read:\t" + stopWatch.toString());
    
    HAZELCAST_INSTANCE.getLifecycleService().kill();
    

    }

    private static abstract class Runnable {

    public void run (){
        for (int i = 0; i < 10000; i++){
            doSomething(i);
        }
    }
    
    protected abstract void doSomething(int i);
    

    }

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions