gpt4 book ai didi

ruby - "-r profile"和 "require ' 配置文件'”有什么区别?

转载 作者:数据小太阳 更新时间:2023-10-29 07:37:52 25 4
gpt4 key购买 nike

我的 Ruby 版本是 1.9.3p448。

我有一个简单的程序:

count = 0
words = File.open('/usr/share/dict/words')

while word = words.gets
word.chomp!
count += 1 if word.length == 12
end

puts "#{count} twelve-character words"

当我用 ruby -r profile test.rb 评估它时,输出是:

7226 twelve-character words
% cumulative self self total
time seconds seconds calls ms/call ms/call name
9.63 0.44 0.44 119095 0.00 0.00 String#chomp!
9.19 0.86 0.42 119095 0.00 0.00 Fixnum#==
6.35 1.15 0.29 119095 0.00 0.00 String#length
5.91 1.42 0.27 119096 0.00 0.00 IO#gets
0.66 1.45 0.03 7226 0.00 0.00 Fixnum#+
0.00 1.45 0.00 2 0.00 0.00 IO#set_encoding
0.00 1.45 0.00 1 0.00 0.00 IO#open
0.00 1.45 0.00 1 0.00 0.00 File#initialize
0.00 1.45 0.00 1 0.00 0.00 Fixnum#to_s
0.00 1.45 0.00 2 0.00 0.00 IO#write
0.00 1.45 0.00 1 0.00 0.00 IO#puts
0.00 1.45 0.00 1 0.00 0.00 Kernel.puts
0.00 4.57 0.00 1 0.00 4570.00 #toplevel

但是,当我在程序的开头添加 require 'profile',然后用 ruby test.rb 对其进行评估时,输出是:

7226 twelve-character words
% cumulative self self total
time seconds seconds calls ms/call ms/call name
25.61 0.63 0.63 119095 0.01 0.01 String#chomp!
16.67 1.04 0.41 119096 0.00 0.00 IO#gets
0.00 1.04 0.00 1 0.00 0.00 Fixnum#to_s
0.00 1.04 0.00 1 0.00 0.00 IO#open
0.00 1.04 0.00 1 0.00 0.00 File#initialize
0.00 1.04 0.00 2 0.00 0.00 IO#write
0.00 1.04 0.00 1 0.00 0.00 IO#puts
0.00 1.04 0.00 1 0.00 0.00 Kernel.puts
0.00 2.46 0.00 1 0.00 2460.00 #toplevel

第二种方式似乎丢失了一些方法,如Fixnum#==Fixnum#+String#lengthIO#set_encoding.

为什么和第一个结果不一样?

最佳答案

根据profile documentation应该没有区别。我创建了一个 bug report为此。

关于ruby - "-r profile"和 "require ' 配置文件'”有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22861559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com