valkey/tests/unit/memefficiency.tcl

38 lines
1.1 KiB
Tcl
Raw Normal View History

2013-08-29 14:23:57 +00:00
proc test_memory_efficiency {range} {
r flushall
set rd [redis_deferring_client]
2013-08-29 14:23:57 +00:00
set base_mem [s used_memory]
set written 0
for {set j 0} {$j < 10000} {incr j} {
set key key:$j
set val [string repeat A [expr {int(rand()*$range)}]]
$rd set $key $val
2013-08-29 14:23:57 +00:00
incr written [string length $key]
incr written [string length $val]
incr written 2 ;# A separator is the minimum to store key-value data.
}
for {set j 0} {$j < 10000} {incr j} {
$rd read ; # Discard replies
}
2013-08-29 14:23:57 +00:00
set current_mem [s used_memory]
set used [expr {$current_mem-$base_mem}]
set efficiency [expr {double($written)/$used}]
return $efficiency
}
start_server {tags {"memefficiency"}} {
foreach {size_range expected_min_efficiency} {
32 0.15
64 0.25
128 0.35
1024 0.75
16384 0.82
2013-08-29 14:23:57 +00:00
} {
test "Memory efficiency with values in range $size_range" {
set efficiency [test_memory_efficiency $size_range]
assert {$efficiency >= $expected_min_efficiency}
}
}
}