active_support / core_ext / numeric / conversions.rb在open-uri中打开非常慢

时间:2013-09-13 13:18:31

标签: ruby

当我需要open-uri和active_support / core_ext / numeric / conversions.rb或active_support / core_ext / big_decimal / conversions.rb时,'打开" http://some.website.com"& #39;变得极其缓慢。 我怎么能避免这个?

Ruby 2.0.0,active_support 4.0.0

EDIT 这是分析结果。有很多Gem :: Dependency#matching_specs(以及其他)调用。

来源(包含转化)

require 'open-uri'
require 'active_support/core_ext/numeric/conversions'
open 'http://stackoverflow.com'

结果

 %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
 21.46     0.56      0.56    22620     0.02     0.11  Gem::Dependency#matching_specs
 13.41     0.91      0.35     4567     0.08     0.76  Array#each
  5.36     1.05      0.14     1500     0.09     0.15  Gem::Version#<=>
  4.98     1.18      0.13     3810     0.03     0.11  Gem::BasicSpecification#contains_requirable_file?
  3.83     1.28      0.10     5353     0.02     0.03  Gem::StubSpecification#activated?
  3.45     1.37      0.09    27604     0.00     0.00  Gem::StubSpecification#name
  3.07     1.45      0.08     1382     0.06     0.33  nil#
  3.07     1.53      0.08     2139     0.04     0.25  Gem::Specification#initialize
  2.68     1.60      0.07      106     0.66     5.85  Kernel#gem_original_require
  2.68     1.67      0.07    21258     0.00     0.00  String#===
...

来源(没有转化)

require 'open-uri'
open 'http://stackoverflow.com'

结果

  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
 36.36     0.08      0.08       46     1.74    10.65  Kernel#gem_original_require
 22.73     0.13      0.05      816     0.06     0.09  nil#
  4.55     0.14      0.01       46     0.22    11.09  Kernel#require
  4.55     0.15      0.01       22     0.45    22.27  Net::BufferedIO#rbuf_fill
  4.55     0.16      0.01        3     3.33     3.33  URI::Parser#split
  4.55     0.17      0.01       88     0.11     0.34  Module#module_eval
  4.55     0.18      0.01      133     0.08     0.45  Object#DelegateClass
  4.55     0.19      0.01      184     0.05     0.11  Gem.find_unresolved_default_spec
  4.55     0.20      0.01     1280     0.01     0.01  Integer#chr
  4.55     0.21      0.01     1280     0.01     0.01  String#%
  4.55     0.22      0.01     1381     0.01     0.01  Module#method_added
...

0 个答案:

没有答案