What is the difference between "-r profile" and "require" profile? "?

My Ruby version is 1.9.3p448.

I have a simple program:

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"

When I evaluate it using ruby -r profile test.rb, the output is:

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

But, when I add require 'profile'at the beginning of the program, and then evaluate it with ruby test.rb, the output is:

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

It seems that the second method has lost some methods, such as Fixnum#==, Fixnum#+, String#lengthand IO#set_encoding.

Why doesn't he have the same result as the first?

+4
source share
1 answer

In accordance with the profile documentation, there should be no difference. For this, I created an error report.

+1
source

Source: https://habr.com/ru/post/1535011/


All Articles