Last active
August 29, 2015 14:21
-
-
Save satoshihirose/a445707b27ba4b7ad05f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("lua script") { | |
it("will be expected to work fast with smembers command execution") { | |
val REDIS_HOST: String = "localhost" | |
val REDIS_PORT: Int = 6379 | |
val DATABASE: Int = 2 | |
lazy val client = new RedisClient(REDIS_HOST, REDIS_PORT, DATABASE) | |
val testKey = "test_key" | |
//|return 1.0 | |
val loopSmembersCode = s""" | |
|for k=1,1000 do | |
| local res = redis.call('SMEMBERS', "${testKey}") | |
|end | |
""".stripMargin | |
val loopSmembersSHAHash = client.scriptLoad(loopSmembersCode).get | |
def execTime[R](str: String)(proc: => R): R = { | |
val start = System.nanoTime() | |
val result = proc | |
val end = System.nanoTime() | |
val time = (end - start) / 1000000D | |
println(s"execution time of ${str}: ${time} [ms]") | |
result | |
} | |
(1 to 1000).foreach(id => client.sadd(testKey, id)) | |
import scala.sys.process._ | |
execTime(s"1000 loop smembers with 1000 members(eval)") { | |
(1 to 1000).foreach(id => """redis-cli -n 2 EVAL "return redis.call('SMEMBERS','test_key')" 0""" !! ) | |
} | |
execTime(s"1000 loop smembers with 1000 members(scala-redis evalBulk)") { | |
client.evalBulk(loopSmembersCode, List(), List()) | |
} | |
execTime(s"1000 loop smembers with 1000 members(scala-redis evalSHA)") { | |
client.evalSHA(loopSmembersSHAHash, List(), List()) | |
} | |
execTime(s"1000 loop smembers with 1000 members(scala-redis smembers)") { | |
(1 to 1000).foreach(id => client.smembers(testKey)) | |
} | |
client.del(testKey) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
execution time of 1000 loop smembers with 1000 members(eval): 76349.003494 [ms] | |
execution time of 1000 loop smembers with 1000 members(scala-redis evalBulk): 7120.779401 [ms] | |
execution time of 1000 loop smembers with 1000 members(scala-redis evalSHA): 7001.60564 [ms] | |
execution time of 1000 loop smembers with 1000 members(scala-redis smembers): 2139.525746 [ms] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment