ritsudo 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2396e7dc48c6005364d5f35a728c22b09cca4a7ec40445cc81984c2e34317c7a
4
- data.tar.gz: 82b0a8c4e870801d707e16ec3e21de34431e67d19f73283f1005f7385238a188
3
+ metadata.gz: a77d5c59f6d7b99726077b003de30cd23f39592f28468db7d026d957e4cfd48a
4
+ data.tar.gz: 83c34af615e1fc84fe88f05ada1ba81fcf4d842f8579f9f17bb23c766e146349
5
5
  SHA512:
6
- metadata.gz: 474cc72036aa278b67344d832556face7ebe1569fdee8ac6601cc493f60e39fccfd668f5a40b4cf2986125cb9cdd4f323e4fd5e0c15e34fa7b81dc6e63d1b57a
7
- data.tar.gz: 40285a426da3b945854f8a3dc94a5b6c7e4832d18f9d28b56e9f9247634dbd71a3aacde37d9b538b62558c0b5d67a22e8ea0c8d83701a1229c8a7d6dd88abaa1
6
+ metadata.gz: 03b861dd1a4d7b1b4c571f6c69a62b513863e307bfd922be35271151ba06b9910284d8162ee8b031ee409e35ba072eefe067236eafd0a842e60ed12b652a7fb2
7
+ data.tar.gz: 10d8668f416cbc181ab5bdbe9e2b7b82c0b3af771eff400bcff04c993bd0955a30cddfaf00d942f5e9f4acf781022b20717c0dfead6ea009a6d013c810ce4501
data/README.md CHANGED
@@ -71,6 +71,13 @@ Ritsudo requests 5 times: https://example.com
71
71
  ritsudo -a https://example.com/page -m "example.com" -C "hoge=fuga"
72
72
  ```
73
73
 
74
+ ### Remove outlier
75
+ -r option removes outliders outside of (stdev * numeric) value.
76
+ ```
77
+ ritsudo -a https://example.com/page -m "example.com" -s #{numeric}
78
+ ```
79
+
80
+
74
81
  #### Problem
75
82
  Headless chrome doesn't support to set cookies before access.
76
83
  So, Ritsudo accesses root path(e.g https://example.com) before each benchmark.
data/lib/ritsudo/cli.rb CHANGED
@@ -11,6 +11,7 @@ module Ritsudo
11
11
  class_option :wait_time, default: 1, type: :numeric, aliases: ['-w']
12
12
  class_option :ua, type: :string, aliases: ['-u']
13
13
  class_option :match, type: :string, aliases: ['-m']
14
+ class_option :outliters_stdev_multiple, type: :numeric, aliases: ['-r']
14
15
 
15
16
  desc "benchmark URL", "benchmark"
16
17
  def benchmark()
@@ -27,7 +28,7 @@ module Ritsudo
27
28
  cookies: options[:cookies]
28
29
  }
29
30
  )
30
- benchmark.collector.report
31
+ benchmark.collector.report(outliters_stdev_multiple: options[:outliters_stdev_multiple])
31
32
  end
32
33
  tasks["benchmark"].options = self.class_options
33
34
  end
@@ -33,14 +33,14 @@ module Ritsudo
33
33
  @misc.add(group, name, value)
34
34
  end
35
35
 
36
- def report
37
- @misc.report
36
+ def report(outliters_stdev_multiple: nil)
37
+ @misc.report(outliters_stdev_multiple: outliters_stdev_multiple)
38
38
  puts ""
39
- @documents.report
39
+ @documents.report(outliters_stdev_multiple: outliters_stdev_multiple)
40
40
  puts ""
41
- @xhrs.report
41
+ @xhrs.report(outliters_stdev_multiple: outliters_stdev_multiple)
42
42
  puts ""
43
- @scripts.report
43
+ @scripts.report(outliters_stdev_multiple: outliters_stdev_multiple)
44
44
  puts ""
45
45
  end
46
46
  end
@@ -0,0 +1,26 @@
1
+ module Ritsudo
2
+ module Result
3
+ module Helper
4
+ def self.remove_outliters(values, stdev_multiple)
5
+ stdev = standard_deviation(values)
6
+ mean = mean(values)
7
+ range = (mean - (stdev * stdev_multiple))..(mean + (stdev * stdev_multiple))
8
+ values.select { |v| range.cover?(v) }
9
+ end
10
+
11
+ def self.mean(values)
12
+ sum = values.sum(0.0)
13
+ mean = sum / values.size
14
+ end
15
+
16
+ def self.variance(values)
17
+ total = values.inject(0) { |sum, v| sum + ((v - mean(values)) ** 2) }
18
+ total.to_f / (values.size - 1)
19
+ end
20
+
21
+ def self.standard_deviation(values)
22
+ Math.sqrt(variance(values))
23
+ end
24
+ end
25
+ end
26
+ end
@@ -11,20 +11,32 @@ module Ritsudo
11
11
  @misc[group][name] << value
12
12
  end
13
13
 
14
- def report
14
+ def report(outliters_stdev_multiple: nil)
15
15
  table_data = []
16
16
  @misc.each do |group, name_and_values|
17
17
  puts "[#{group}]"
18
- name_and_values.each do |name, values|
19
- table_data << {
18
+
19
+ name_and_values.each do |name, all_values|
20
+ use_remove_outsiders = outliters_stdev_multiple && all_values.size > 1
21
+ if use_remove_outsiders
22
+ values = Ritsudo::Result::Helper.remove_outliters(all_values, outliters_stdev_multiple)
23
+ else
24
+ values = all_values
25
+ end
26
+
27
+ result = {
20
28
  name: name,
21
- avg: (values.sum(0.0) / values.length).round(2),
22
- max: values.max.round(2),
23
- min: values.min.round(2),
24
- count: values.size
29
+ avg: (values.sum(0.0) / values.length)&.round(2),
30
+ max: values.max&.round(2),
31
+ min: values.min&.round(2),
32
+ count: values.size,
33
+ outsiders: all_values.size - values.size
25
34
  }
35
+
36
+
37
+ table_data << result
26
38
  end
27
- Formatador.display_table(table_data, [:name, :avg, :max, :min, :count])
39
+ Formatador.display_table(table_data, [:name, :avg, :max, :min, :count, :outsiders])
28
40
  end
29
41
  end
30
42
  end
@@ -1,6 +1,8 @@
1
1
  module Ritsudo
2
2
  module Result
3
3
  module Uncompletable
4
+ include Ritsudo::Result::Helper
5
+
4
6
  def add(request)
5
7
  @requests ||= []
6
8
  @uncompleted ||= Hash.new
@@ -17,29 +19,42 @@ module Ritsudo
17
19
  raise NotImplementedError
18
20
  end
19
21
 
20
- def report
22
+ def report(outliters_stdev_multiple: nil)
21
23
  puts "[#{name}]"
22
24
  table_data = []
23
25
  (@requests || []).uniq.each do |url|
24
26
  if @completed[url] && !@completed[url].empty?
25
- avg = (@completed[url].sum(0.0) / @completed[url].length).round(2)
26
- max = @completed[url].max.round(2)
27
- min = @completed[url].min.round(2)
28
- count = @completed[url].size
27
+ all_request_times = @completed[url]
28
+ use_remove_outliters = outliters_stdev_multiple && all_request_times.size > 1
29
+
30
+ if use_remove_outliters
31
+ request_times = Ritsudo::Result::Helper.remove_outliters(all_request_times, outliters_stdev_multiple)
32
+ else
33
+ request_times = all_request_times
34
+ end
35
+
36
+ avg = (request_times.sum(0.0) / request_times.length)&.round(2)
37
+ max = request_times.max&.round(2)
38
+ min = request_times.min&.round(2)
39
+ count = request_times.size
29
40
  else
30
41
  avg = max = min = count = "-"
31
42
  end
32
43
 
33
- table_data << {
34
- url: url[0..100],
35
- avg: avg,
36
- max: max,
37
- min: min,
38
- count: count,
39
- uncompleted: @uncompleted[url]
44
+ result = {
45
+ url: url[0..100],
46
+ avg: avg,
47
+ max: max,
48
+ min: min,
49
+ count: count,
50
+ uncompleted: @uncompleted[url],
51
+ outliters: all_request_times.size - request_times.size
40
52
  }
53
+
54
+
55
+ table_data << result
41
56
  end
42
- Formatador.display_table(table_data, [:url, :avg, :max, :min, :count, :uncompleted])
57
+ Formatador.display_table(table_data, [:url, :avg, :max, :min, :count, :uncompleted, :outliters])
43
58
  end
44
59
  end
45
60
  end
@@ -1,3 +1,3 @@
1
1
  module Ritsudo
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
data/lib/ritsudo.rb CHANGED
@@ -9,6 +9,7 @@ require 'ritsudo/request'
9
9
  require 'ritsudo/benchmark'
10
10
  require 'ritsudo/collector'
11
11
  require 'ritsudo/result'
12
+ require 'ritsudo/result/helper'
12
13
  require 'ritsudo/result/base'
13
14
  require 'ritsudo/result/uncompletable'
14
15
  require 'ritsudo/result/misc'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ritsudo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - shingo morita
@@ -146,6 +146,7 @@ files:
146
146
  - lib/ritsudo/result.rb
147
147
  - lib/ritsudo/result/base.rb
148
148
  - lib/ritsudo/result/documents.rb
149
+ - lib/ritsudo/result/helper.rb
149
150
  - lib/ritsudo/result/misc.rb
150
151
  - lib/ritsudo/result/scripts.rb
151
152
  - lib/ritsudo/result/uncompletable.rb