Created
December 21, 2016 14:56
-
-
Save meoooh/8686d254b05d0a2ed2ccb635bf00b6d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hhash = {} | |
(0..10000000).each{ |i| hhash[i] = rand }; | |
parallel_sum = Parallel.map(hhash.each_slice(1000)) do |ele| # https://github.com/grosser/parallel | |
ele.sum{|value| value.last} | |
end.sum | |
puts parallel_sum | |
normal_sum = hhash.sum{|_,v| v} | |
puts normal_sum | |
parallel_sum == normal_sum # false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hhash = {} | |
(0..10000000).each{ |i| hhash[i] = 1 }; | |
parallel_sum = Parallel.map(hhash.each_slice(1000)) do |ele| # https://github.com/grosser/parallel | |
ele.sum{|value| value.last} | |
end.sum | |
puts parallel_sum | |
normal_sum = hhash.sum{|_,v| v} | |
puts normal_sum | |
parallel_sum == normal_sum # true |
require 'parallel'
require 'active_support/all'
따라서 해보실 분은 위와 같이 코드를 추가해보세요.
RORLAB 슬랙 채널 http://rorlab.slackarchive.io/question_answer/-/1479210726.000646/1482365225.000055/1482365225000055/ 에서 이야기 하고 있습니다. 빅넘버와 래셔널을 참고하세요.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
추가적으로
위와 같은 현상이 있네요.
1/3 = 0.33333333(무한소수) 를 sum하면 두가지 방식의 sum 값이 다르고
1/2 = 0.5를 sum하면 두가지 방식의 sum의 값이 같네요.