Class: Puma::Benchmark::PrintResult

Inherits:
Object
  • Object
show all
Defined in:
lib/puma/benchmark/print_result.rb

Instance Method Summary collapse

Instance Method Details

#call(result) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/puma/benchmark/print_result.rb', line 4

def call(result)
  set_columns
  write_divider
  write_header
  write_divider
  result.each { |h| write_line(h) }
  write_divider
end

#set_columnsObject



13
14
15
16
17
# File 'lib/puma/benchmark/print_result.rb', line 13

def set_columns
  @columns = {workers: {:label=>"No. of workers",    :width=>15},
              threads: {:label=>"No. of threads",    :width=>15},
              req_per_sec: {:label=>"No. of requests/sec",    :width=>20}}
end

#write_dividerObject



23
24
25
# File 'lib/puma/benchmark/print_result.rb', line 23

def write_divider
  puts "+-#{ @columns.map { |_,g| "-"*g[:width] }.join("-+-") }-+"
end

#write_headerObject



19
20
21
# File 'lib/puma/benchmark/print_result.rb', line 19

def write_header
  puts "| #{ @columns.map { |_,g| g[:label].ljust(g[:width]) }.join(' | ') } |"
end

#write_line(h) ⇒ Object



27
28
29
30
# File 'lib/puma/benchmark/print_result.rb', line 27

def write_line(h)
  str = h.keys.map { |k| h[k].ljust(@columns[k][:width]) }.join(" | ")
  puts "| #{str} |"
end