// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package cache.hazelcast;

import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;

public class TestPerformance {
    private static final int N = 10000;
    private static void test(IMap<String,Integer> cache) {
        // put speed
        long t1 = System.currentTimeMillis();
        for(int i = 0; i < N; i++) {
            cache.put("K#" + (i + 1), i + 1);
        }
        long t2 = System.currentTimeMillis();
        System.out.printf("%d puts per second\n", N * 1000 / (t2 - t1));
    }
    private static final int REP = 5;
    public static void main(String[] args) throws Exception {
        ClientConfig cfg = new ClientConfig();
        HazelcastInstance cli = HazelcastClient.newHazelcastClient(cfg);
        IMap<String,Integer> cache = cli.getMap("performance_cache");
        for(int i = 0; i < REP; i++) {
            test(cache);
        }
        cli.shutdown();
    }
}
