11 - profiling your application.rb

来自「O Reilly Ruby Cookbook source code」· RB 代码 · 共 49 行

RB
49
字号
#!/usr/bin/env ruby# sequence_counter.rbrequire 'profile'total = 0# Count the letter sequences containing an a, b, or c.('a'..'zz').each do |seq|  ['a', 'b', 'c'].each do |i|    if seq.index(i)      total += 1      break    end  endendputs "Total: #{total}"#---$ ruby sequence_counter.rbTotal: 150  %   cumulative   self              self     total time   seconds   seconds    calls  ms/call  ms/call  name 54.55     0.30      0.30      702     0.43     0.50  Array#each 32.73     0.48      0.18        1   180.00   550.00  Range#each  7.27     0.52      0.04     1952     0.02     0.02  String#index  3.64     0.54      0.02      702     0.03     0.03  String#succ  1.82     0.55      0.01      150     0.07     0.07  Fixnum#+...#---#!/usr/bin/env ruby# sequence_counter2.rbrequire 'profile'total = 0# Count the letter sequences containing an a, b, or c.('a'..'zz').each {|seq| total +=1 if seq =~ /[abc]/ }puts "Total: #{total}"#---$ ruby sequence_counter2.rbTotal: 150  %   cumulative   self              self     total time   seconds   seconds    calls  ms/call  ms/call  name 83.33     0.05      0.05        1    50.00    60.00  Range#each 16.67     0.06      0.01      150     0.07     0.07  Fixnum#+  0.00     0.06      0.00        1     0.00     0.00  Fixnum#to_s...#---re = /[abc]/('a'..'zz').each {|seq| total +=1 if seq =~ re }#---

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?