SuperMean
Arithmetic mean from array written in C.
Installation
Add this line to your application's Gemfile:
gem 'super_mean'
And then execute:
$ bundle
Or install it yourself as:
$ gem install super_mean
Usage
This gem just adds #mean
method for arrays.
[1, 2, 3].mean
# => 2.0
Benchmark
Conditions:
ary = (0..100_000_000).to_a
Benchmark.bmbm(7) do |x|
x.report('Ruby') do
ary.inject(&:+) / ary.size
end
x.report('C') do
ary.mean
end
end
Results:
Rehearsal ----------------------------------------------
Ruby 8.690000 0.070000 8.760000 ( 9.720472)
C 0.480000 0.000000 0.480000 ( 0.536145)
------------------------------------- total: 9.240000sec
user system total real
Ruby 8.950000 0.240000 9.190000 ( 10.445315)
C 0.440000 0.000000 0.440000 ( 0.460983)
Contributing
- Fork it (https://github.com/droptheplot/super_mean/fork)
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
License
The gem is available as open source under the terms of the MIT License.