parallel_enumerable 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/lib/parallel_enumerable.rb +5 -0
- data/lib/parallel_enumerable/active_record.rb +7 -0
- data/lib/parallel_enumerable/enumerable.rb +7 -0
- data/lib/parallel_enumerable/proxy.rb +26 -0
- data/lib/parallel_enumerable/version.rb +3 -0
- data/parallel_enumerable.gemspec +23 -0
- data/spec/enumerable_spec.rb +45 -0
- data/spec/spec_helper.rb +1 -0
- metadata +93 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Gabriel Naiman
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# ParallelEnumerable
|
2
|
+
|
3
|
+
Extend Enumerable module with parallel gem features
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'parallel_enumerable'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install parallel_enumerable
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
[1,2,3].parallel.each do |i|
|
22
|
+
puts i
|
23
|
+
end
|
24
|
+
|
25
|
+
## Supported methods
|
26
|
+
|
27
|
+
- each
|
28
|
+
- each_with_index
|
29
|
+
- map
|
30
|
+
- map_with_index
|
31
|
+
|
32
|
+
## Specify threds or processes
|
33
|
+
|
34
|
+
enumerable.parallel(in_threads: 4).each { ... }
|
35
|
+
or
|
36
|
+
enumerable.parallel(in_processes: 4).each { ... }
|
37
|
+
|
38
|
+
## ActiveRelation extension
|
39
|
+
|
40
|
+
Model.scoped.parallel.each { ... }
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ParallelEnumerable
|
2
|
+
class Proxy
|
3
|
+
|
4
|
+
def initialize(enumerable, options={})
|
5
|
+
@enumerable = enumerable
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def each(&block)
|
10
|
+
Parallel.each(@enumerable, @options, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def each_with_index(&block)
|
14
|
+
Parallel.each_with_index(@enumerable, @options, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def map(&block)
|
18
|
+
Parallel.map(@enumerable, @options, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def map_with_index(&block)
|
22
|
+
Parallel.map_with_index(@enumerable, @options, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'parallel_enumerable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "parallel_enumerable"
|
8
|
+
gem.version = ParallelEnumerable::VERSION
|
9
|
+
gem.authors = ["Gabriel Naiman"]
|
10
|
+
gem.email = ["gabynaiman@gmail.com"]
|
11
|
+
gem.description = 'Extends enumerable module with parallel'
|
12
|
+
gem.summary = 'Extends enumerable module with parallel'
|
13
|
+
gem.homepage = 'https://github.com/gabynaiman/parallel_enumerable'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'parallel'
|
21
|
+
|
22
|
+
gem.add_development_dependency 'rspec'
|
23
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Enumerable do
|
4
|
+
|
5
|
+
it 'should support parallelized each' do
|
6
|
+
array = []
|
7
|
+
10.times.parallel(in_threads: 2).each do |i|
|
8
|
+
sleep((10-i)/100.0)
|
9
|
+
array << i
|
10
|
+
end
|
11
|
+
|
12
|
+
array.should eq [1, 0, 3, 2, 5, 4, 7, 6, 9, 8]
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should support parallelized each_with_index' do
|
16
|
+
hash = {}
|
17
|
+
%w(a b c d e f).parallel(in_threads: 2).each_with_index do |letter, i|
|
18
|
+
sleep((10-i)/100.0)
|
19
|
+
hash[i] = letter
|
20
|
+
end
|
21
|
+
|
22
|
+
hash.should eq 1 => 'b', 0 => 'a', 3 => 'd', 2 => 'c', 5 => 'f', 4 => 'e'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should support parallelized map' do
|
26
|
+
array = 10.times.parallel(in_threads: 3).map do |i|
|
27
|
+
sleep(0.001)
|
28
|
+
Thread.current.hash
|
29
|
+
end
|
30
|
+
|
31
|
+
array.should have(10).items
|
32
|
+
array.uniq.should have(3).items
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should support parallelized map_with_index' do
|
36
|
+
array = %w(a b c d e f).parallel(in_threads: 3).map_with_index do |letter, i|
|
37
|
+
sleep(0.001)
|
38
|
+
{Thread.current.hash => "#{letter}_#{i}"}
|
39
|
+
end
|
40
|
+
|
41
|
+
array.map { |hash| hash.values.first }.should eq %w(a_0 b_1 c_2 d_3 e_4 f_5)
|
42
|
+
array.map { |hash| hash.keys.first }.uniq.should have(3).items
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'parallel_enumerable'
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: parallel_enumerable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gabriel Naiman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: parallel
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Extends enumerable module with parallel
|
47
|
+
email:
|
48
|
+
- gabynaiman@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/parallel_enumerable.rb
|
59
|
+
- lib/parallel_enumerable/active_record.rb
|
60
|
+
- lib/parallel_enumerable/enumerable.rb
|
61
|
+
- lib/parallel_enumerable/proxy.rb
|
62
|
+
- lib/parallel_enumerable/version.rb
|
63
|
+
- parallel_enumerable.gemspec
|
64
|
+
- spec/enumerable_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: https://github.com/gabynaiman/parallel_enumerable
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.24
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Extends enumerable module with parallel
|
90
|
+
test_files:
|
91
|
+
- spec/enumerable_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
has_rdoc:
|