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

import redis.clients.jedis.Jedis;

public class TestPerformance {
    private static final int N = 10000;
    private static void test(Jedis cache) {
        // put speed
        long t1 = System.currentTimeMillis();
        for(int i = 0; i < N; i++) {
            cache.set("K#" + (i + 1), Integer.toString(i + 1));
        }
        long t2 = System.currentTimeMillis();
        System.out.printf("%d puts per second\n", N * 1000 / (t2 - t1));
    }
    private static final int PERFORMANCE_CACHE = 1;
    private static final int REP = 5;
    public static void main(String[] args) throws Exception {
        Jedis cache = new Jedis("localhost", 6379);
        cache.select(PERFORMANCE_CACHE);
        for(int i = 0; i < REP; i++) {
            test(cache);
        }
        cache.close();
    }
}
