From 30de0a5fc4ffd0936e4d5e1999cf5c342d0af3a7 Mon Sep 17 00:00:00 2001 From: Matt Ranney Date: Thu, 16 Sep 2010 23:52:47 -0700 Subject: [PATCH] Add performance tests similar to redis-benchmark. --- test.js | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/test.js b/test.js index 19b6e38df4..8b9a6addc6 100644 --- a/test.js +++ b/test.js @@ -65,6 +65,104 @@ tests.FLUSHDB = function () { client.dbsize(last(name, require_number(0, name))); }; +tests.PING_10K = function () { + var name = "PING_10K", i = 10000; + + do { + client.PING(); + i -= 1; + } while (i > 1); + client.PING([], function (err, res) { + assert.strictEqual("PONG", res); + console.log(name + " " + (10000 / ((Date.now() - cur_start)/1000)).toFixed(2) + " reqs/sec"); + next(name); + }); +}; + +tests.SET_10K = function () { + var name = "SET_10K", i = 10000; + + do { + client.SET("foo_rand000000000000", "xxx"); + i -= 1; + } while (i > 1); + client.SET("foo_rand000000000000", "xxx", function (err, res) { + assert.strictEqual("OK", res); + console.log(name + " " + (10000 / ((Date.now() - cur_start)/1000)).toFixed(2) + " reqs/sec"); + next(name); + }); +}; + +tests.GET_10K = function () { + var name = "GET_10K", i = 10000; + + do { + client.GET("foo_rand000000000000"); + i -= 1; + } while (i > 1); + client.GET("foo_rand000000000000", function (err, res) { + assert.strictEqual("xxx", res.toString()); + console.log(name + " " + (10000 / ((Date.now() - cur_start)/1000)).toFixed(2) + " reqs/sec"); + next(name); + }); +}; + +tests.INCR_10K = function () { + var name = "INCR_10K", i = 10000; + + do { + client.INCR("counter_rand000000000000"); + i -= 1; + } while (i > 1); + client.INCR("counter_rand000000000000", function (err, res) { + assert.strictEqual(10000, res); + console.log(name + " " + (10000 / ((Date.now() - cur_start)/1000)).toFixed(2) + " reqs/sec"); + next(name); + }); +}; + +tests.LPUSH_10K = function () { + var name = "LPUSH_10K", i = 10000; + + do { + client.LPUSH("mylist", "bar"); + i -= 1; + } while (i > 1); + client.LPUSH("mylist", "bar", function (err, res) { + assert.strictEqual(10000, res); + console.log(name + " " + (10000 / ((Date.now() - cur_start)/1000)).toFixed(2) + " reqs/sec"); + next(name); + }); +}; + +tests.LRANGE_10K_100 = function () { + var name = "LRANGE_10K_100", i = 1000; + + do { + client.LRANGE("mylist", 0, 99); + i -= 1; + } while (i > 1); + client.LRANGE("mylist", 0, 99, function (err, res) { +// assert.strictEqual("bar", res.toString()); + console.log(name + " " + (1000 / ((Date.now() - cur_start)/1000)).toFixed(2) + " reqs/sec"); + next(name); + }); +}; + +tests.LRANGE_10K_500 = function () { + var name = "LRANGE_10K_500", i = 1000; + + do { + client.LRANGE("mylist", 0, 499); + i -= 1; + } while (i > 1); + client.LRANGE("mylist", 0, 499, function (err, res) { +// assert.strictEqual("bar", res.toString()); + console.log(name + " " + (1000 / ((Date.now() - cur_start)/1000)).toFixed(2) + " reqs/sec"); + next(name); + }); +}; + tests.EXISTS = function () { var name = "EXISTS"; client.del("foo", "foo2", require_number_any(name));