forkjoin 1.0.0-java → 1.0.1-java
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/examples/wordcount.rb +25 -14
- data/forkjoin.gemspec +1 -1
- metadata +1 -1
data/examples/wordcount.rb
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
require 'forkjoin'
|
2
|
+
require 'benchmark'
|
2
3
|
|
3
|
-
|
4
|
+
file = ARGV.shift
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
5.times do
|
7
|
+
Benchmark.bm do |bm|
|
8
|
+
bm.report do
|
9
|
+
pool = ForkJoin::Pool.new
|
10
|
+
map_futures = nil
|
11
|
+
File.open(file) do |f|
|
12
|
+
map_futures = pool.invoke_all(
|
13
|
+
f.each_line.map { |line| -> { line.split.map { |word| [word,1] } } }
|
14
|
+
)
|
15
|
+
end
|
16
|
+
counts = map_futures.map(&:get).inject({}) { |map, value|
|
17
|
+
value.each { |k, v| (map[k] ||= []) << v }
|
18
|
+
map
|
19
|
+
}
|
20
|
+
reduced_futures = pool.invoke_all(
|
21
|
+
counts.map { |k, vs| -> { [k, vs.size] } }
|
22
|
+
)
|
23
|
+
# reduced_futures.map(&:get).each{|value|
|
24
|
+
# puts "%s %d\n" % value
|
25
|
+
# }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/forkjoin.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{forkjoin}
|
5
|
-
s.version = "1.0.
|
5
|
+
s.version = "1.0.1"
|
6
6
|
s.authors = ["Charles Oliver Nutter", "Nakamura Hiroshi"]
|
7
7
|
s.date = Time.now.strftime('%Y-%m-%d')
|
8
8
|
s.description = "A JRuby extension to efficiently wrap the JSR166 Fork/Join framework."
|