parallel_runner 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5 -1
- data/README.md +3 -3
- data/gem/parallel_runner-0.0.2.gem +0 -0
- data/lib/parallel_runner.rb +2 -3
- data/parallel_runner.gemspec +1 -1
- data/spec/parallel_runner_helper.rb +2 -2
- data/spec/parallel_runner_spec.rb +6 -6
- metadata +3 -2
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -8,19 +8,19 @@
|
|
8
8
|
For list:
|
9
9
|
|
10
10
|
require 'parallel_runner'
|
11
|
-
['a', 'b', 'c'].
|
11
|
+
['a', 'b', 'c'].each_parallel do |value|
|
12
12
|
# your processing
|
13
13
|
end
|
14
14
|
|
15
15
|
require 'parallel_runner'
|
16
|
-
['a', 'b', 'c'].
|
16
|
+
['a', 'b', 'c'].each_parallel do |value, index|
|
17
17
|
# your processing
|
18
18
|
end
|
19
19
|
|
20
20
|
For map:
|
21
21
|
|
22
22
|
require 'parallel_runner'
|
23
|
-
{:name => 'alice', age => 17}.
|
23
|
+
{:name => 'alice', age => 17}.each_parallel do |key, value|
|
24
24
|
# your processing
|
25
25
|
end
|
26
26
|
|
Binary file
|
data/lib/parallel_runner.rb
CHANGED
@@ -4,7 +4,6 @@ require 'thread'
|
|
4
4
|
module ParallelRunner
|
5
5
|
def self.each(object, concurency = 10, qsize = nil, &block)
|
6
6
|
q = qsize ? SizedQueue.new(qsize) : Queue.new
|
7
|
-
threads = []
|
8
7
|
producer = Thread.start(q, concurency) do |pq, pc|
|
9
8
|
if object.instance_of? Array
|
10
9
|
object.each_with_index {|value, index| pq.enq([[value, index], true])}
|
@@ -29,13 +28,13 @@ module ParallelRunner
|
|
29
28
|
end
|
30
29
|
|
31
30
|
class Hash
|
32
|
-
def
|
31
|
+
def each_parallel(concurency = 10, qsize = nil, &block)
|
33
32
|
ParallelRunner.each(self, concurency, qsize, &block)
|
34
33
|
end
|
35
34
|
end
|
36
35
|
|
37
36
|
class Array
|
38
|
-
def
|
37
|
+
def each_parallel(concurency = 10, qsize = nil, &block)
|
39
38
|
ParallelRunner.each(self, concurency, qsize, &block)
|
40
39
|
end
|
41
40
|
end
|
data/parallel_runner.gemspec
CHANGED
@@ -27,10 +27,10 @@ def map
|
|
27
27
|
}
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def time_by_each_parallel
|
31
31
|
agent = Mechanize.new
|
32
32
|
exec_time {
|
33
|
-
list.
|
33
|
+
list.each_parallel do |url|
|
34
34
|
site = agent.get(url)
|
35
35
|
html = site.root.xpath("//title")[0].inner_html
|
36
36
|
html.should_not be_nil
|
@@ -3,34 +3,34 @@ require 'parallel_runner_helper'
|
|
3
3
|
|
4
4
|
describe 'parallel_runner' do
|
5
5
|
it "Iterate list in parallel" do
|
6
|
-
list.
|
6
|
+
list.each_parallel do |val|
|
7
7
|
val.should_not be_empty
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
it "Iterate list with index in parallel" do
|
12
|
-
list.
|
12
|
+
list.each_parallel do |val, index|
|
13
13
|
val.should_not be_empty
|
14
14
|
index.to_s.should match(/^\d$/)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
it "Iterate map in parallel" do
|
19
|
-
map.
|
19
|
+
map.each_parallel do |key, value|
|
20
20
|
key.should_not be_empty
|
21
21
|
value.should_not be_empty
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
it "faster than Array#each" do
|
26
|
-
time_by_each.should be >
|
26
|
+
time_by_each.should be > time_by_each_parallel
|
27
27
|
end
|
28
28
|
|
29
29
|
it "faster than Array#each_with_index" do
|
30
|
-
time_by_each_with_index.should be >
|
30
|
+
time_by_each_with_index.should be > time_by_each_parallel
|
31
31
|
end
|
32
32
|
|
33
33
|
it "faster than Hash#each" do
|
34
|
-
time_by_each_by_map.should be >
|
34
|
+
time_by_each_by_map.should be > time_by_each_parallel
|
35
35
|
end
|
36
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parallel_runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-17 00:00:00.000000000 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
description: Simple parallel processing library.
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- README.md
|
26
26
|
- Rakefile
|
27
27
|
- gem/parallel_runner-0.0.1.gem
|
28
|
+
- gem/parallel_runner-0.0.2.gem
|
28
29
|
- lib/parallel_runner.rb
|
29
30
|
- parallel_runner.gemspec
|
30
31
|
- spec/parallel_runner_helper.rb
|