Cruby 2.1 빠르진 않아요.
지난번과 마찬가지로 조사 대상은
뻔한 일
결실
가로축은 시간이기 때문에 길수록 느리다.

선택한 처리는 이렇게 생각해 낸다.
그다지 붐비지 않아서 판본에 따라 적당히 차별화된 것을 썼다.
2.1 늦어지는 것을 선택한 것은 아니다.
다음은 리허설을 생략하겠습니다.
ruby 1.9
"ruby 1.9.3p545 (2014-02-24 revision 45159) [x86_64-darwin13.0.0]"
size : 2000
user system total real
pack_unpack 1.200000 0.020000 1.220000 ( 1.222390)
hugenum 0.840000 0.050000 0.890000 ( 0.885420)
delete_if_and_push 5.930000 0.000000 5.930000 ( 5.935082)
modify_string 3.310000 0.010000 3.320000 ( 3.314836)
ruby 2.0
"ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-darwin13.3.0]"
size : 2000
user system total real
pack_unpack 1.230000 0.050000 1.280000 ( 1.274881)
hugenum 0.940000 0.050000 0.990000 ( 0.991847)
delete_if_and_push 5.760000 0.000000 5.760000 ( 5.763749)
modify_string 3.530000 0.000000 3.530000 ( 3.536681)
ruby 2.1
"ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]"
size : 2000
user system total real
pack_unpack 2.470000 0.050000 2.520000 ( 2.518461)
hugenum 0.850000 0.010000 0.860000 ( 0.860112)
delete_if_and_push 7.220000 0.010000 7.230000 ( 7.229943)
modify_string 3.530000 0.000000 3.530000 ( 3.526038)
jruby1.7.12 --1.9
"jruby 1.7.12 (1.9.3p392) 2014-04-15 643e292 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_07-b10 [darwin-x86_64]"
size : 2000
user system total real
pack_unpack 1.730000 0.010000 1.740000 ( 1.710000)
hugenum 2.510000 0.000000 2.510000 ( 2.491000)
delete_if_and_push 2.600000 0.010000 2.610000 ( 2.554000)
modify_string 1.820000 0.010000 1.830000 ( 1.822000)
jruby1.7.12 --2.0
"jruby 1.7.12 (2.0.0p195) 2014-04-15 643e292 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_07-b10 [darwin-x86_64]"
size : 2000
user system total real
pack_unpack 1.760000 0.010000 1.770000 ( 1.744000)
hugenum 2.530000 0.000000 2.530000 ( 2.518000)
delete_if_and_push 3.320000 0.030000 3.350000 ( 2.883000)
modify_string 1.850000 0.000000 1.850000 ( 1.847000)
이용 프로그램
#encode:utf-8
(p RUBY_DESCRIPTION) rescue p "1.8.x or former"
require "benchmark"
def pack_unpack(size)
s=Array.new(30000){ [*"a".."z"].sample }.join
size.times do
s=[s].pack("m").unpack("m").first
s=s.unpack("N*").pack("V*")
end
end
def hugenum(size)
a=10
size.times do
a=(a**a % 8191 )+10
end
end
def delete_if_and_push(size)
s=[]
(2..size).each do |x|
s.each{ |e| e<<1 unless e[0] % x ==0 }
s.delete_if{ |e| e[0] % x ==0 }
s<<(s.size.to_s*(s.size+1)) while s.size<size
end
end
def modify_string( size )
srand 1
s=[*"\u1d400".."\u1d500"].zip( (?a..?z).cycle ).flatten.join
(size/5).times do
s[rand(s.size)]="a\u1f200"*size
end
end
def run_bench( size )
puts "size : #{size}"
m=[ :pack_unpack, :hugenum, :delete_if_and_push, :modify_string ]
len = m.map(&:to_s).map(&:size).max
Benchmark.bmbm(len) do |x|
m.each do |s|
x.report(s.to_s){
self.send(s, size)
}
end
end
end
run_bench( 2000 )
결론
뜻밖에 모르다.
Reference
이 문제에 관하여(Cruby 2.1 빠르진 않아요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/Nabetani/items/47d357cc7f80f5c42f0d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)