memefficiency.tcl 986 B

1234567891011121314151617181920212223242526272829303132
  1. proc test_memory_efficiency {range} {
  2. r flushall
  3. set base_mem [s used_memory]
  4. set written 0
  5. for {set j 0} {$j < 10000} {incr j} {
  6. set key key:$j
  7. set val [string repeat A [expr {int(rand()*$range)}]]
  8. r set $key $val
  9. incr written [string length $key]
  10. incr written [string length $val]
  11. incr written 2 ;# A separator is the minimum to store key-value data.
  12. }
  13. set current_mem [s used_memory]
  14. set used [expr {$current_mem-$base_mem}]
  15. set efficiency [expr {double($written)/$used}]
  16. return $efficiency
  17. }
  18. start_server {tags {"memefficiency"}} {
  19. foreach {size_range expected_min_efficiency} {
  20. 32 0.15
  21. 64 0.25
  22. 128 0.35
  23. 1024 0.75
  24. 16384 0.82
  25. } {
  26. test "Memory efficiency with values in range $size_range" {
  27. set efficiency [test_memory_efficiency $size_range]
  28. assert {$efficiency >= $expected_min_efficiency}
  29. }
  30. }
  31. }