class RailsApiBenchmark::Endpoint
Attributes
method[R]
name[R]
route[R]
title[R]
Public Class Methods
new(opts)
click to toggle source
# File lib/rails_api_benchmark/endpoint.rb, line 11 def initialize(opts) @name = opts[:name] @route = opts[:route] @method = opts[:method] @title = opts[:title] @results = {} @results_folder = "#{RailsApiBenchmark.config.results_folder}/#{@name}" end
Public Instance Methods
benchmark()
click to toggle source
# File lib/rails_api_benchmark/endpoint.rb, line 26 def benchmark benchmark_cmd = RailsApiBenchmark.config.bench_cmd opts = RailsApiBenchmark.config.all.merge(route: @route) output = `#{benchmark_cmd % opts}` regexps = RailsApiBenchmark.config.regexps regexps.each { |r| @results[r[:key]] = output.scan(r[:regexp]).flatten.first } end
query()
click to toggle source
# File lib/rails_api_benchmark/endpoint.rb, line 36 def query curl_cmd = RailsApiBenchmark.config.curl_cmd opts = RailsApiBenchmark.config.all.merge(route: @route) @results[:response] = JSON.pretty_generate(JSON.parse(`#{curl_cmd % opts}`)) end
run_benchmark()
click to toggle source
# File lib/rails_api_benchmark/endpoint.rb, line 20 def run_benchmark query benchmark @results end
Private Instance Methods
write_results()
click to toggle source
# File lib/rails_api_benchmark/endpoint.rb, line 45 def write_results FileUtils.mkdir_p(@results_folder) if @response File.open(File.join(@results_folder, 'response.json'), 'w+') do |f| f.write(@response) end end unless @results.empty? File.open(File.join(@results_folder, 'response.json'), 'w+') do |f| f.write(@response) end end end