[Groonga-commit] droonga/http-benchmark at f1695a5 [master] Output result of GradualRunner as a CSV

アーカイブの一覧に戻る

Kenji Okimoto okimo****@clear*****
Mon Oct 7 18:30:41 JST 2013


On 2013年10月07日 18:15, YUKI Hiroshi wrote:
> Author
>     YUKI Hiroshi <shimoda �� clear-code.com>
> Date
>     2013-10-07 18:15:30 +0900 (Mon, 07 Oct 2013)
> New Revision
>     f1695a5d4f2c8be722383e3e5ecee5cb6f9668e9 <https://github.com/droonga/http-benchmark/commit/f1695a5d4f2c8be722383e3e5ecee5cb6f9668e9>
> Message
>
>     Output result of GradualRunner as a CSV
>
> Modified files
>
>       * lib/droonga/http-benchmark/formatter.rb <https://github.com/droonga/http-benchmark/commit/f1695a5d4f2c8be722383e3e5ecee5cb6f9668e9#diff-0>
>       * lib/droonga/http-benchmark/gradual-runner.rb <https://github.com/droonga/http-benchmark/commit/f1695a5d4f2c8be722383e3e5ecee5cb6f9668e9#diff-1>
>
>    Modified: lib/droonga/http-benchmark/formatter.rb (+29 -0)
> ===================================================================
>
>
> @@ -16,6 +16,35 @@module Droonga
>             puts "  max:     #{result[:max_elapsed_time} sec"
>             puts "  average: #{result[:average_elapsed_time]} sec"
>           end
> +
> +        def output_gradual_results(results)
> +          http_statuses = []
> +          results.each do |n_clients, result|
> +            http_statuses += result[:responses].keys
> +          end
> +          http_statuses.uniq!
> +          http_statuses.sort!
> +
> +          puts "n_clients,total_n_requests,queries_per_second," +
> +                 "#{http_statuses.join(",")}," +
> +                 "min_elapsed_time,max_elapsed_time,average_elapsed_time"
> +          results.each do |n_clients, result|
> +            response_statuses = http_statuses.collect do |status|
> +              if result[:responses].include?(status)
> +                result[:responses][status]
> +              else
> +                0
> +              end
> +            end
> +            puts "#{n_clients}," +
> +                   "#{result[:total_n_requests]}," +
> +                   "#{result[:queries_per_second]}," +
> +                   "#{response_statuses.join(",")}," +
> +                   "#{result[:min_elapsed_time]}," +
> +                   "#{result[:max_elapsed_time]}," +
> +                   "#{result[:average_elapsed_time]},"
> +          end
> +        end
>         end

一行にたくさんの変数を埋め込むときは String#% を使うときれいに書けることがありますよ。

"%d,%f,%s,%d,%d,%f" % [...]

http://doc.ruby-lang.org/ja/2.0.0/method/String/i/=25.html

全部ハッシュになってるなら↑の一番下にある名前を付ける方法が使えます。


>       end
>     end
>
>    Modified: lib/droonga/http-benchmark/gradual-runner.rb (+11 -2)
> ===================================================================
>
> 	
>
> @@ -11,10 +11,19 @@module Droonga
>           @start_n_clients = params[:start_n_clients]
>           @end_n_clients = params[:end_n_clients]
>           @step = params[:step]
> -        @results = []
> +      end
> +
> +      def run
> +        run_benchmarks
> +        Formatter.output_gradual_results(@results)
> +      end
> +
> +      private
> +      def run_benchmarks
> +        @results = {}
>           @start_n_clients.step(@end_n_clients, @step) do |n_clients|
>             benchmark = Runner.new(params.merge(:n_clients => n_clients))
> -          @results << benchmark.run
> +          @results[n_clients] = benchmark.run
>           end
>         end
>       end
>
>
>
> _______________________________________________
> Groonga-commit mailing list
> Groonga-commit �� lists.sourceforge.jp
> http://lists.sourceforge.jp/mailman/listinfo/groonga-commit
>


-- 
Kenji Okimoto <okimoto �� clear-code.com>




More information about the Groonga-commit mailing list
アーカイブの一覧に戻る