enumerable-statistics 0.1.0 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +47 -0
  3. data/.yardopts +2 -0
  4. data/CHANGELOG.md +30 -0
  5. data/LICENSE +21 -0
  6. data/README.md +68 -4
  7. data/Rakefile +15 -0
  8. data/bench/array_value_counts.yml +42 -0
  9. data/bench/enum_value_counts.yml +42 -0
  10. data/bench/hash_value_counts.yml +42 -0
  11. data/bench/mean.yml +30 -0
  12. data/bench/sum.yml +29 -0
  13. data/bench/variance.yml +39 -0
  14. data/enumerable-statistics.gemspec +16 -6
  15. data/ext/enumerable/statistics/extension/extconf.rb +12 -0
  16. data/ext/enumerable/statistics/extension/statistics.c +1696 -89
  17. data/images/benchmark.png +0 -0
  18. data/lib/enumerable/statistics.rb +1 -1
  19. data/lib/enumerable_statistics.rb +2 -0
  20. data/lib/enumerable_statistics/histogram.rb +5 -0
  21. data/lib/enumerable_statistics/version.rb +9 -0
  22. data/templates/default/layout/html/headers.erb +36 -0
  23. data/yard/templates/mathjax/class/dot/setup.rb +6 -0
  24. data/yard/templates/mathjax/class/dot/superklass.erb +3 -0
  25. data/yard/templates/mathjax/class/html/constructor_details.erb +8 -0
  26. data/yard/templates/mathjax/class/html/setup.rb +1 -0
  27. data/yard/templates/mathjax/class/html/subclasses.erb +4 -0
  28. data/yard/templates/mathjax/class/setup.rb +36 -0
  29. data/yard/templates/mathjax/class/text/setup.rb +11 -0
  30. data/yard/templates/mathjax/class/text/subclasses.erb +5 -0
  31. data/yard/templates/mathjax/constant/text/header.erb +11 -0
  32. data/yard/templates/mathjax/constant/text/setup.rb +3 -0
  33. data/yard/templates/mathjax/docstring/html/abstract.erb +4 -0
  34. data/yard/templates/mathjax/docstring/html/deprecated.erb +1 -0
  35. data/yard/templates/mathjax/docstring/html/index.erb +5 -0
  36. data/yard/templates/mathjax/docstring/html/note.erb +6 -0
  37. data/yard/templates/mathjax/docstring/html/private.erb +4 -0
  38. data/yard/templates/mathjax/docstring/html/returns_void.erb +1 -0
  39. data/yard/templates/mathjax/docstring/html/text.erb +1 -0
  40. data/yard/templates/mathjax/docstring/html/todo.erb +6 -0
  41. data/yard/templates/mathjax/docstring/setup.rb +51 -0
  42. data/yard/templates/mathjax/docstring/text/abstract.erb +2 -0
  43. data/yard/templates/mathjax/docstring/text/deprecated.erb +2 -0
  44. data/yard/templates/mathjax/docstring/text/index.erb +2 -0
  45. data/yard/templates/mathjax/docstring/text/note.erb +4 -0
  46. data/yard/templates/mathjax/docstring/text/private.erb +2 -0
  47. data/yard/templates/mathjax/docstring/text/returns_void.erb +1 -0
  48. data/yard/templates/mathjax/docstring/text/text.erb +1 -0
  49. data/yard/templates/mathjax/docstring/text/todo.erb +4 -0
  50. data/yard/templates/mathjax/fulldoc/html/css/common.css +1 -0
  51. data/yard/templates/mathjax/fulldoc/html/css/full_list.css +58 -0
  52. data/yard/templates/mathjax/fulldoc/html/css/style.css +481 -0
  53. data/yard/templates/mathjax/fulldoc/html/frames.erb +17 -0
  54. data/yard/templates/mathjax/fulldoc/html/full_list.erb +37 -0
  55. data/yard/templates/mathjax/fulldoc/html/full_list_class.erb +2 -0
  56. data/yard/templates/mathjax/fulldoc/html/full_list_file.erb +7 -0
  57. data/yard/templates/mathjax/fulldoc/html/full_list_method.erb +10 -0
  58. data/yard/templates/mathjax/fulldoc/html/js/app.js +243 -0
  59. data/yard/templates/mathjax/fulldoc/html/js/full_list.js +216 -0
  60. data/yard/templates/mathjax/fulldoc/html/js/jquery.js +4 -0
  61. data/yard/templates/mathjax/fulldoc/html/setup.rb +242 -0
  62. data/yard/templates/mathjax/layout/dot/header.erb +6 -0
  63. data/yard/templates/mathjax/layout/dot/setup.rb +14 -0
  64. data/yard/templates/mathjax/layout/html/breadcrumb.erb +11 -0
  65. data/yard/templates/mathjax/layout/html/files.erb +11 -0
  66. data/yard/templates/mathjax/layout/html/footer.erb +5 -0
  67. data/yard/templates/mathjax/layout/html/headers.erb +15 -0
  68. data/yard/templates/mathjax/layout/html/index.erb +2 -0
  69. data/yard/templates/mathjax/layout/html/layout.erb +38 -0
  70. data/yard/templates/mathjax/layout/html/listing.erb +4 -0
  71. data/yard/templates/mathjax/layout/html/objects.erb +32 -0
  72. data/yard/templates/mathjax/layout/html/script_setup.erb +4 -0
  73. data/yard/templates/mathjax/layout/html/search.erb +13 -0
  74. data/yard/templates/mathjax/layout/html/setup.rb +87 -0
  75. data/yard/templates/mathjax/method/html/header.erb +17 -0
  76. data/yard/templates/mathjax/method/setup.rb +3 -0
  77. data/yard/templates/mathjax/method/text/header.erb +1 -0
  78. data/yard/templates/mathjax/method_details/html/header.erb +3 -0
  79. data/yard/templates/mathjax/method_details/html/method_signature.erb +25 -0
  80. data/yard/templates/mathjax/method_details/html/source.erb +10 -0
  81. data/yard/templates/mathjax/method_details/setup.rb +10 -0
  82. data/yard/templates/mathjax/method_details/text/header.erb +10 -0
  83. data/yard/templates/mathjax/method_details/text/method_signature.erb +12 -0
  84. data/yard/templates/mathjax/method_details/text/setup.rb +10 -0
  85. data/yard/templates/mathjax/module/dot/child.erb +1 -0
  86. data/yard/templates/mathjax/module/dot/dependencies.erb +3 -0
  87. data/yard/templates/mathjax/module/dot/header.erb +6 -0
  88. data/yard/templates/mathjax/module/dot/info.erb +14 -0
  89. data/yard/templates/mathjax/module/dot/setup.rb +14 -0
  90. data/yard/templates/mathjax/module/html/attribute_details.erb +10 -0
  91. data/yard/templates/mathjax/module/html/attribute_summary.erb +8 -0
  92. data/yard/templates/mathjax/module/html/box_info.erb +43 -0
  93. data/yard/templates/mathjax/module/html/children.erb +8 -0
  94. data/yard/templates/mathjax/module/html/constant_summary.erb +11 -0
  95. data/yard/templates/mathjax/module/html/defines.erb +3 -0
  96. data/yard/templates/mathjax/module/html/header.erb +5 -0
  97. data/yard/templates/mathjax/module/html/inherited_attributes.erb +14 -0
  98. data/yard/templates/mathjax/module/html/inherited_constants.erb +8 -0
  99. data/yard/templates/mathjax/module/html/inherited_methods.erb +19 -0
  100. data/yard/templates/mathjax/module/html/item_summary.erb +40 -0
  101. data/yard/templates/mathjax/module/html/method_details_list.erb +9 -0
  102. data/yard/templates/mathjax/module/html/method_summary.erb +14 -0
  103. data/yard/templates/mathjax/module/html/methodmissing.erb +12 -0
  104. data/yard/templates/mathjax/module/html/pre_docstring.erb +1 -0
  105. data/yard/templates/mathjax/module/setup.rb +164 -0
  106. data/yard/templates/mathjax/module/text/children.erb +10 -0
  107. data/yard/templates/mathjax/module/text/class_meths_list.erb +8 -0
  108. data/yard/templates/mathjax/module/text/extends.erb +8 -0
  109. data/yard/templates/mathjax/module/text/header.erb +7 -0
  110. data/yard/templates/mathjax/module/text/includes.erb +8 -0
  111. data/yard/templates/mathjax/module/text/instance_meths_list.erb +8 -0
  112. data/yard/templates/mathjax/module/text/setup.rb +12 -0
  113. data/yard/templates/mathjax/onefile/html/files.erb +5 -0
  114. data/yard/templates/mathjax/onefile/html/headers.erb +6 -0
  115. data/yard/templates/mathjax/onefile/html/layout.erb +29 -0
  116. data/yard/templates/mathjax/onefile/html/readme.erb +3 -0
  117. data/yard/templates/mathjax/onefile/html/setup.rb +61 -0
  118. data/yard/templates/mathjax/root/dot/child.erb +3 -0
  119. data/yard/templates/mathjax/root/dot/setup.rb +5 -0
  120. data/yard/templates/mathjax/root/html/setup.rb +1 -0
  121. data/yard/templates/mathjax/tags/html/example.erb +11 -0
  122. data/yard/templates/mathjax/tags/html/index.erb +3 -0
  123. data/yard/templates/mathjax/tags/html/option.erb +24 -0
  124. data/yard/templates/mathjax/tags/html/overload.erb +14 -0
  125. data/yard/templates/mathjax/tags/html/see.erb +8 -0
  126. data/yard/templates/mathjax/tags/html/tag.erb +20 -0
  127. data/yard/templates/mathjax/tags/setup.rb +55 -0
  128. data/yard/templates/mathjax/tags/text/example.erb +12 -0
  129. data/yard/templates/mathjax/tags/text/index.erb +1 -0
  130. data/yard/templates/mathjax/tags/text/option.erb +20 -0
  131. data/yard/templates/mathjax/tags/text/overload.erb +19 -0
  132. data/yard/templates/mathjax/tags/text/see.erb +11 -0
  133. data/yard/templates/mathjax/tags/text/tag.erb +13 -0
  134. metadata +170 -19
  135. data/.travis.yml +0 -19
  136. data/lib/enumerable/statistics/version.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9bbba060f2298fae081d18782b237d693663558c
4
- data.tar.gz: f4b5aa2e3bdaed71938a0bb4fb699f9d04daf3e5
2
+ SHA256:
3
+ metadata.gz: e03fe8a749cc70b480ba4ab50285b63b3829cf88e3b24c1fef315d1db26caebb
4
+ data.tar.gz: ca1ba053b0aa133190f170a253d16d5153033e37d27851084d2484276ae4da48
5
5
  SHA512:
6
- metadata.gz: 6b2cc2848db0d8103e09bf770d565be0fcfe360f6dbb45b18ebbbca48027d0f96ae6488a90f3f0ddf3111a82200e14e3b07509f3f7e6cd5ce2fa115350f34224
7
- data.tar.gz: 2fdc7b8b992a2194aabd6aa82af286d93d03772f385ed1927f2c412eaf2667dd9c9472a65b438c9a1a9660012a014bd879ec16e5dc934ac76d9a543a936539cd
6
+ metadata.gz: 5c0f2f284ec0565ee1b15661a1abfed165f4ce26f36a8fd30fd8ca66a0a92d4be118ef114de3d02a2a567688b46f579b06f6704c6f01b4bb02dcb4ebcdb73de4
7
+ data.tar.gz: a0ba31fe6bdc536cdf7152840cd69e6ef47763904fb4e4cf1ec7498c7748a7d246f7a32c90e1d524bd9932af8df9cb942194db3eb593de6979171c5258c8fd67
@@ -0,0 +1,47 @@
1
+ name: CI
2
+
3
+ on:
4
+ - push
5
+
6
+ jobs:
7
+ cruby:
8
+ name: Test
9
+ runs-on: ${{ matrix.os }}
10
+
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os:
15
+ - ubuntu-latest
16
+ - macos-latest
17
+ - windows-latest
18
+ ruby:
19
+ - 3.0
20
+ - 2.7
21
+ - 2.6
22
+ - 2.5
23
+ - 2.4
24
+ - debug
25
+ exclude:
26
+ - os: windows-latest
27
+ ruby: 3.0
28
+ - os: windows-latest
29
+ ruby: debug
30
+
31
+ steps:
32
+ - uses: actions/checkout@v2
33
+
34
+ - name: Setup Ruby
35
+ uses: ruby/setup-ruby@v1
36
+ with:
37
+ ruby-version: ${{ matrix.ruby }}
38
+
39
+ - run: gem install bundler
40
+ - run: bundle install
41
+
42
+ - run: rake --trace compile
43
+
44
+ - run: rake build
45
+ - run: gem install pkg/*gem
46
+
47
+ - run: rake spec
@@ -0,0 +1,2 @@
1
+ --markup markdown
2
+ -p templates
@@ -0,0 +1,30 @@
1
+ # 2.0.2
2
+
3
+ - Support Ruby 3.0
4
+
5
+ # 2.0.1
6
+
7
+ - Fix a bug of `histogram` (#9)
8
+
9
+ # 2.0.0
10
+
11
+ - Add `value_counts` method in Array, Hash, and Enumerable
12
+ - Add `median` method in Array
13
+ - Add `percentile` method in Array
14
+ - Add `histogram` method in Array
15
+
16
+ # 1.0.1
17
+
18
+ - Add `mean_variance` method in Array class and Enumerable module
19
+ - Add optimized implementation of `mean_variance` method for a Hash
20
+ - Add the following methods, implemented by using `mean_variance`, in Array class and Enumerable module
21
+ - `mean`
22
+ - `variance`
23
+ - `stddev`
24
+ - `mean_stddev`
25
+ - Add `sum` method in Array class and Enumerable module when Ruby < 2.4, that is almost same as introduced in Ruby 2.4
26
+ - Add optimized implementation of `sum` method for a Range with integer ends and a Hash, that is almost same as introduced in Ruby 2.4
27
+
28
+ # 1.0.0
29
+
30
+ - This version was yanked due to documentation issue
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Kenta Murata
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Enumerable::Statistics
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/enumerable/statistics`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://travis-ci.org/mrkn/enumerable-statistics.svg?branch=master)](https://travis-ci.org/mrkn/enumerable-statistics)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Enumerable::Statistics provides some methods to calculate statistical summary in arrays and enumerables.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,7 +22,71 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ You should load this library by the following line in your script at first.
26
+
27
+ ```ruby
28
+ require 'enumerable/statistics'
29
+ ```
30
+
31
+ The following methods are supplied by this library:
32
+
33
+ - `Array#mean`, `Enumerable#mean`
34
+ - Calculates a mean of values in an array or an enumerable
35
+ - `Array#variance`, `Enumerable#variance`
36
+ - Calculates a variance of values in an array or an enumerable
37
+ - `Array#stdev`, `Enumerable#stdev`
38
+ - Calculates a standard deviation of values in an array or an enumerable
39
+ - `Array#mean_variance`, `Enumerable#mean_variance`
40
+ - Calculates a mean and a variance simultaneously
41
+ - `Array#mean_stdev`, `Enumerable#mean_stdev`
42
+ - Calculates a mean and a standard deviation simultaneously
43
+ - `Array#median`
44
+ - Calculates a median of values in an array
45
+ - `Array#percentile(q)`
46
+ - Calculates a percentile or percentiles of values in an array
47
+ - `Array#value_counts`, `Enumerable#value_counts`, and `Hash#value_counts`
48
+ - Count how many items for each value in the container
49
+ - `Array#histogram`
50
+ - Calculate histogram of the values in the array
51
+
52
+ Moreover, for Ruby < 2.4, `Array#sum` and `Enumerable#sum` are provided.
53
+
54
+ All methods scan a collection once to calculate statistics and preserve precision as possible.
55
+
56
+ ## Performance
57
+
58
+ ```
59
+ $ bundle exec rake bench
60
+ # sum
61
+ Warming up --------------------------------------
62
+ inject 1.545k i/100ms
63
+ while 2.342k i/100ms
64
+ sum 11.009k i/100ms
65
+ Calculating -------------------------------------
66
+ inject 15.016k (± 9.6%) i/s - 75.705k in 5.098723s
67
+ while 22.238k (±16.2%) i/s - 107.732k in 5.068156s
68
+ sum 112.992k (± 6.9%) i/s - 572.468k in 5.091868s
69
+ # mean
70
+ Warming up --------------------------------------
71
+ inject 1.578k i/100ms
72
+ while 2.057k i/100ms
73
+ mean 9.855k i/100ms
74
+ Calculating -------------------------------------
75
+ inject 15.347k (± 8.6%) i/s - 77.322k in 5.076009s
76
+ while 21.669k (±14.5%) i/s - 106.964k in 5.074312s
77
+ mean 108.861k (± 8.9%) i/s - 542.025k in 5.021786s
78
+ # variance
79
+ Warming up --------------------------------------
80
+ inject 586.000 i/100ms
81
+ while 826.000 i/100ms
82
+ variance 8.475k i/100ms
83
+ Calculating -------------------------------------
84
+ inject 6.187k (± 6.7%) i/s - 31.058k in 5.043418s
85
+ while 8.597k (± 7.4%) i/s - 42.952k in 5.024587s
86
+ variance 84.702k (± 8.5%) i/s - 423.750k in 5.039936s
87
+ ```
88
+
89
+ ![](./images/benchmark.png)
26
90
 
27
91
  ## Development
28
92
 
@@ -32,5 +96,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
96
 
33
97
  ## Contributing
34
98
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/enumerable-statistics.
99
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mrkn/enumerable-statistics.
36
100
 
data/Rakefile CHANGED
@@ -6,4 +6,19 @@ task :default => :spec
6
6
 
7
7
  Rake::ExtensionTask.new('enumerable/statistics/extension')
8
8
 
9
+ directory 'lib/enumerable/statistics'
10
+
9
11
  RSpec::Core::RakeTask.new(:spec)
12
+
13
+ task :spec => :compile
14
+
15
+ task :bench do
16
+ puts "# sum\n"
17
+ system('benchmark-driver bench/sum.yml')
18
+
19
+ puts "# mean\n"
20
+ system('benchmark-driver bench/mean.yml')
21
+
22
+ puts "# variance\n"
23
+ system('benchmark-driver bench/variance.yml')
24
+ end
@@ -0,0 +1,42 @@
1
+ contexts:
2
+ - name: "1.1.0.dev"
3
+ gems:
4
+ enumerable-statistics: "1.1.0.dev"
5
+ require: false
6
+ prelude: |-
7
+ require 'enumerable/statistics'
8
+ - name: "HEAD"
9
+ prelude: |-
10
+ require 'bundler/setup'
11
+ require 'enumerable/statistics'
12
+ prelude: |-
13
+ n = 1000
14
+ chars = ('a'..'m').to_a
15
+ ary = Array.new(n) { chars.sample }
16
+ benchmark:
17
+ inject: |-
18
+ ary.inject(Hash.new(0)) { |h, x| h[x] += 1; h }
19
+ unsort_keepna: |-
20
+ ary.value_counts(sort: false, dropna: false)
21
+ unsort_dropna: |-
22
+ ary.value_counts(sort: false, dropna: true)
23
+ sort_keepna: |-
24
+ ary.value_counts(sort: true, dropna: false)
25
+ sort_dropna: |-
26
+ ary.value_counts(sort: true, dropna: true)
27
+ norm_unsort_keepna: |-
28
+ ary.value_counts(normalize: true, sort: false, dropna: false)
29
+ norm_unsort_dropna: |-
30
+ ary.value_counts(normalize: true, sort: false, dropna: true)
31
+ norm_sort_keepna: |-
32
+ ary.value_counts(normalize: true, sort: true, dropna: false)
33
+ norm_sort_dropna: |-
34
+ ary.value_counts(normalize: true, sort: true, dropna: true)
35
+ sort_asc_keepna: |-
36
+ ary.value_counts(sort: true, ascending: true, dropna: false)
37
+ sort_asc_dropna: |-
38
+ ary.value_counts(sort: true, ascending: true, dropna: true)
39
+ norm_sort_asc_keepna: |-
40
+ ary.value_counts(normalize: true, sort: true, ascending: true, dropna: false)
41
+ norm_sort_asc_dropna: |-
42
+ ary.value_counts(normalize: true, sort: true, ascending: true, dropna: true)
@@ -0,0 +1,42 @@
1
+ contexts:
2
+ - name: "1.1.0.dev"
3
+ gems:
4
+ enumerable-statistics: "1.1.0.dev"
5
+ require: false
6
+ prelude: |-
7
+ require 'enumerable/statistics'
8
+ - name: "HEAD"
9
+ prelude: |-
10
+ require 'bundler/setup'
11
+ require 'enumerable/statistics'
12
+ prelude: |-
13
+ n = 1000
14
+ chars = ('a'..'m').to_a
15
+ enum = Array.new(n) { chars.sample }.each
16
+ benchmark:
17
+ inject: |-
18
+ enum.inject(Hash.new(0)) { |h, x| h[x] += 1; h }
19
+ unsort_keepna: |-
20
+ enum.value_counts(sort: false, dropna: false)
21
+ unsort_dropna: |-
22
+ enum.value_counts(sort: false, dropna: true)
23
+ sort_keepna: |-
24
+ enum.value_counts(sort: true, dropna: false)
25
+ sort_dropna: |-
26
+ enum.value_counts(sort: true, dropna: true)
27
+ norm_unsort_keepna: |-
28
+ enum.value_counts(normalize: true, sort: false, dropna: false)
29
+ norm_unsort_dropna: |-
30
+ enum.value_counts(normalize: true, sort: false, dropna: true)
31
+ norm_sort_keepna: |-
32
+ enum.value_counts(normalize: true, sort: true, dropna: false)
33
+ norm_sort_dropna: |-
34
+ enum.value_counts(normalize: true, sort: true, dropna: true)
35
+ sort_asc_keepna: |-
36
+ enum.value_counts(sort: true, ascending: true, dropna: false)
37
+ sort_asc_dropna: |-
38
+ enum.value_counts(sort: true, ascending: true, dropna: true)
39
+ norm_sort_asc_keepna: |-
40
+ enum.value_counts(normalize: true, sort: true, ascending: true, dropna: false)
41
+ norm_sort_asc_dropna: |-
42
+ enum.value_counts(normalize: true, sort: true, ascending: true, dropna: true)
@@ -0,0 +1,42 @@
1
+ contexts:
2
+ - name: "1.1.0.dev"
3
+ gems:
4
+ enumerable-statistics: "1.1.0.dev"
5
+ require: false
6
+ prelude: |-
7
+ require 'enumerable/statistics'
8
+ - name: "HEAD"
9
+ prelude: |-
10
+ require 'bundler/setup'
11
+ require 'enumerable/statistics'
12
+ prelude: |-
13
+ n = 1000
14
+ chars = ('a'..'m').to_a
15
+ hash = Array.new(n) { chars.sample }.each_with_index.to_h
16
+ benchmark:
17
+ inject: |-
18
+ hash.inject(Hash.new(0)) { |h, (k, v)| h[v] += 1; h }
19
+ unsort_keepna: |-
20
+ hash.value_counts(sort: false, dropna: false)
21
+ unsort_dropna: |-
22
+ hash.value_counts(sort: false, dropna: true)
23
+ sort_keepna: |-
24
+ hash.value_counts(sort: true, dropna: false)
25
+ sort_dropna: |-
26
+ hash.value_counts(sort: true, dropna: true)
27
+ norm_unsort_keepna: |-
28
+ hash.value_counts(normalize: true, sort: false, dropna: false)
29
+ norm_unsort_dropna: |-
30
+ hash.value_counts(normalize: true, sort: false, dropna: true)
31
+ norm_sort_keepna: |-
32
+ hash.value_counts(normalize: true, sort: true, dropna: false)
33
+ norm_sort_dropna: |-
34
+ hash.value_counts(normalize: true, sort: true, dropna: true)
35
+ sort_asc_keepna: |-
36
+ hash.value_counts(sort: true, ascending: true, dropna: false)
37
+ sort_asc_dropna: |-
38
+ hash.value_counts(sort: true, ascending: true, dropna: true)
39
+ norm_sort_asc_keepna: |-
40
+ hash.value_counts(normalize: true, sort: true, ascending: true, dropna: false)
41
+ norm_sort_asc_dropna: |-
42
+ hash.value_counts(normalize: true, sort: true, ascending: true, dropna: true)
@@ -0,0 +1,30 @@
1
+ contexts:
2
+ - name: "master"
3
+ prelude: |-
4
+ require 'bundler/setup'
5
+ require 'enumerable/statistics'
6
+ prelude: |-
7
+ n = 1000
8
+ ary = Array.new(n) { rand }
9
+ benchmark:
10
+ inject: mean = ary.inject(:+) / n.to_f
11
+ while: |-
12
+ i, mean = 0, 0
13
+ while i < n
14
+ mean += ary[i]
15
+ i += 1
16
+ end
17
+ mean /= n.to_f
18
+ pure_ruby: |-
19
+ i, f, c = 0, 0.0, 0.0, 0.0, 0.0
20
+ while i < n
21
+ x = ary[i]
22
+ y = x - c
23
+ t = f + y
24
+ c = (t - f) - y
25
+ f = t
26
+
27
+ i += 1
28
+ end
29
+ mean = f / n
30
+ c_ext: mean = ary.mean
@@ -0,0 +1,29 @@
1
+ contexts:
2
+ - name: "master"
3
+ prelude: |-
4
+ require 'bundler/setup'
5
+ require 'enumerable/statistics'
6
+ prelude: |-
7
+ n = 1000
8
+ ary = Array.new(n) { rand }
9
+ benchmark:
10
+ inject: sum = ary.inject(:+)
11
+ while: |-
12
+ i, sum = 0, 0
13
+ while i < n
14
+ sum += ary[i]
15
+ i += 1
16
+ end
17
+ pure_ruby: |-
18
+ i, f, c = 0, 0.0, 0.0, 0.0, 0.0
19
+ while i < n
20
+ x = ary[i]
21
+ y = x - c
22
+ t = f + y
23
+ c = (t - f) - y
24
+ f = t
25
+
26
+ i += 1
27
+ end
28
+ sum = f
29
+ sum: sum = ary.sum
@@ -0,0 +1,39 @@
1
+ contexts:
2
+ - name: "master"
3
+ prelude: |-
4
+ require 'bundler/setup'
5
+ require 'enumerable/statistics'
6
+ prelude: |-
7
+ n = 1000
8
+ ary = Array.new(n) { rand }
9
+ benchmark:
10
+ inject: |-
11
+ mean = ary.mean
12
+ var = ary.inject(0.0) { |sum, x|
13
+ sum += (x - mean) ** 2
14
+ } / (n - 1).to_f
15
+ while: |-
16
+ mean = ary.mean
17
+ i, var = 0, 0
18
+ while i < n
19
+ var += (ary[i] - mean) ** 2
20
+ i += 1
21
+ end
22
+ var /= n.to_f
23
+ pure_ruby: |-
24
+ i, m, m2, f, c = 0, 0.0, 0.0, 0.0, 0.0
25
+ while i < n
26
+ x = ary[i]
27
+ y = x - c
28
+ t = f + y
29
+ c = (t - f) - y
30
+ f = t
31
+
32
+ delta = x - m
33
+ m += delta / i
34
+ m2 += delta * (x - m)
35
+
36
+ i += 1
37
+ end
38
+ var = m2 / n
39
+ c_ext: var = ary.variance