super_mean 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a9ce267bf6ce8a12e8c179f6eb3d6ec696e42afc
4
+ data.tar.gz: 46cdecdd79aefdbf35ce8124bae8f74caf960763
5
+ SHA512:
6
+ metadata.gz: 325abb8b71429b2f698b9b35a5b3273bb1882a40b96d9c07e7e3f09d743645c9e9e887dbac31a9cbef225d9dc6defcd72ef7f7408b3a45a366900d3e0de08ef3
7
+ data.tar.gz: e29d180a572b580b6a3d1ff272473ef537eb48cdc8ec945c34307e73e5123a12441b8584db9c3c46ff79a8c8ef92da3630433097e4ec984bb96f063e98062603
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Sergey Novikov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ # SuperMean
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/super_mean.svg)](https://badge.fury.io/rb/super_mean)
4
+
5
+ Arithmetic mean from array written in C.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'super_mean'
13
+ ```
14
+
15
+ And then execute:
16
+ ```bash
17
+ $ bundle
18
+ ```
19
+
20
+ Or install it yourself as:
21
+ ```bash
22
+ $ gem install super_mean
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ This gem just adds `#mean` method for arrays.
28
+
29
+ ```ruby
30
+ [1, 2, 3].mean
31
+ # => 2.0
32
+ ```
33
+
34
+ ## Benchmark
35
+
36
+ Conditions:
37
+
38
+ ```ruby
39
+ ary = (0..100_000_000).to_a
40
+
41
+ Benchmark.bmbm(7) do |x|
42
+ x.report('Ruby') do
43
+ ary.inject(&:+) / ary.size
44
+ end
45
+
46
+ x.report('C') do
47
+ ary.mean
48
+ end
49
+ end
50
+ ```
51
+
52
+ Results:
53
+
54
+ ```shell
55
+ Rehearsal ----------------------------------------------
56
+ Ruby 8.690000 0.070000 8.760000 ( 9.720472)
57
+ C 0.480000 0.000000 0.480000 ( 0.536145)
58
+ ------------------------------------- total: 9.240000sec
59
+
60
+ user system total real
61
+ Ruby 8.950000 0.240000 9.190000 ( 10.445315)
62
+ C 0.440000 0.000000 0.440000 ( 0.460983)
63
+ ```
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it (https://github.com/droptheplot/super_mean/fork)
68
+ 2. Create your feature branch (git checkout -b my-new-feature)
69
+ 3. Commit your changes (git commit -am 'Add some feature')
70
+ 4. Push to the branch (git push origin my-new-feature)
71
+ 5. Create new Pull Request
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require 'rake/extensiontask'
2
+ require 'rubygems/package_task'
3
+
4
+ Rake::ExtensionTask.new('super_mean') do |ext|
5
+ ext.lib_dir = 'lib/super_mean'
6
+ end
@@ -0,0 +1,5 @@
1
+ require 'mkmf'
2
+
3
+ have_header('ruby.h') or missing('ruby.h')
4
+
5
+ create_makefile('super_mean')
@@ -0,0 +1,26 @@
1
+ #include <ruby.h>
2
+
3
+ VALUE
4
+ super_mean_ary_mean(int argc, const VALUE *argv, VALUE ary)
5
+ {
6
+ double result = 0.0;
7
+ long i, length = RARRAY_LEN(ary);
8
+ VALUE *ptr = RARRAY_PTR(ary);
9
+
10
+ for(i = 0; i < length; i++) {
11
+ result += NUM2DBL(ptr[i]);
12
+ }
13
+
14
+ result = result / length;
15
+
16
+ return rb_float_new(result);
17
+ }
18
+
19
+ void
20
+ Init_super_mean(void)
21
+ {
22
+ VALUE ary;
23
+
24
+ ary = rb_define_class("Array", rb_cObject);
25
+ rb_define_method(ary, "mean", super_mean_ary_mean, -1);
26
+ }
@@ -0,0 +1,4 @@
1
+ module SuperMean
2
+ end
3
+
4
+ require_relative '../ext/super_mean/super_mean'
@@ -0,0 +1,3 @@
1
+ module SuperMean
2
+ VERSION = '0.0.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: super_mean
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Novikov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: awesome_print
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake-compiler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - novikov359@gmail.com
72
+ executables: []
73
+ extensions:
74
+ - ext/super_mean/extconf.rb
75
+ extra_rdoc_files: []
76
+ files:
77
+ - MIT-LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - ext/super_mean/extconf.rb
81
+ - ext/super_mean/super_mean.c
82
+ - lib/super_mean.rb
83
+ - lib/super_mean/super_mean.bundle
84
+ - lib/super_mean/version.rb
85
+ homepage: https://github.com/droptheplot/super_mean
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.6.4
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Arithmetic mean from array written in C.
109
+ test_files: []
110
+ has_rdoc: