1
1
# frozen_string_literal: true
2
+
2
3
BENCHMARK_ROOT = File . dirname ( __FILE__ )
3
4
REDIS_ROOT = File . join ( BENCHMARK_ROOT , ".." , "lib" )
4
5
5
- $: << REDIS_ROOT
6
+ $LOAD_PATH << REDIS_ROOT
6
7
require 'redis'
7
8
require 'benchmark'
8
9
@@ -16,7 +17,7 @@ def shift_from_argv
16
17
value = ARGV . shift
17
18
unless value
18
19
show_usage
19
- exit - 1
20
+ exit ( - 1 )
20
21
end
21
22
value
22
23
end
@@ -25,48 +26,48 @@ def shift_from_argv
25
26
start_index = shift_from_argv . to_i
26
27
end_index = shift_from_argv . to_i
27
28
sleep_msec = shift_from_argv . to_i
28
- sleep_duration = sleep_msec / 1000.0
29
+ sleep_duration = sleep_msec / 1000.0
29
30
30
31
redis = Redis . new
31
32
32
33
case operation
33
- when :initialize
34
+ when :initialize
34
35
35
- start_index . upto ( end_index ) do |i |
36
- redis [ i ] = 0
37
- end
36
+ start_index . upto ( end_index ) do |i |
37
+ redis [ i ] = 0
38
+ end
38
39
39
- when :clear
40
+ when :clear
40
41
41
- start_index . upto ( end_index ) do |i |
42
- redis . delete ( i )
43
- end
42
+ start_index . upto ( end_index ) do |i |
43
+ redis . delete ( i )
44
+ end
44
45
45
- when :read , :write
46
+ when :read , :write
46
47
47
- puts "Starting to #{ operation } at segment #{ end_index + 1 } "
48
+ puts "Starting to #{ operation } at segment #{ end_index + 1 } "
48
49
49
- loop do
50
- t1 = Time . now
51
- start_index . upto ( end_index ) do |i |
52
- case operation
53
- when :read
54
- redis . get ( i )
55
- when :write
56
- redis . incr ( i )
57
- else
58
- raise "Unknown operation: #{ operation } "
59
- end
60
- sleep sleep_duration
50
+ loop do
51
+ t1 = Time . now
52
+ start_index . upto ( end_index ) do |i |
53
+ case operation
54
+ when :read
55
+ redis . get ( i )
56
+ when :write
57
+ redis . incr ( i )
58
+ else
59
+ raise "Unknown operation: #{ operation } "
61
60
end
62
- t2 = Time . now
63
-
64
- requests_processed = end_index - start_index
65
- time = t2 - t1
66
- puts "#{ t2 . strftime ( "%H:%M" ) } [segment #{ end_index + 1 } ] : Processed #{ requests_processed } requests in #{ time } seconds - #{ ( requests_processed /time ) . round } requests/sec"
61
+ sleep sleep_duration
67
62
end
63
+ t2 = Time . now
64
+
65
+ requests_processed = end_index - start_index
66
+ time = t2 - t1
67
+ puts "#{ t2 . strftime ( '%H:%M' ) } [segment #{ end_index + 1 } ] : Processed #{ requests_processed } requests " \
68
+ "in #{ time } seconds - #{ ( requests_processed / time ) . round } requests/sec"
69
+ end
68
70
69
71
else
70
- raise "Unknown operation: #{ operation } "
72
+ raise "Unknown operation: #{ operation } "
71
73
end
72
-
0 commit comments