安装宝石比源慢得多

时间:2016-01-12 21:55:11

标签: ruby rubygems rvm

运行已安装的gem比运行它的本地源代码要慢得多。

已安装的gem:

$ time wmctile switch_to Thunderbird

real  0m0.682s
user  0m0.491s
sys 0m0.091s

本地来源:

$ time ./work/wmctile/bin/wmctile switch_to Thunderbird

real  0m0.197s
user  0m0.118s
sys 0m0.064s

为什么呢?可能是因为RVM,还是这个"功能"一般的红宝石宝石?有没有办法加快速度?

编辑:生成的bin文件

$ which wmctile
/home/some_user_name/.rvm/gems/ruby-2.1.2/bin/wmctile

$ cat $( which wmctile )
#!/usr/bin/env ruby_executable_hooks
#
# This file was generated by RubyGems.
#
# The application 'wmctile' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
    version = $1
    ARGV.shift
  end
end

gem 'wmctile', version
load Gem.bin_path('wmctile', 'wmctile', version)

1 个答案:

答案 0 :(得分:0)

只要设置了rvm ruby​​,RVM就会在路径中放置Ruby版本和gemset的正确目录。我的PATH从这开始:

/Users/kbennett/.rvm/gems/ruby-2.3.0/bin
/Users/kbennett/.rvm/gems/ruby-2.3.0@global/bin
/Users/kbennett/.rvm/rubies/ruby-2.3.0/bin
/Users/kbennett/.rvm/bin

所以我认为它是操作系统,而不是Ruby本身负责延迟。您可以通过在该gem bin目录中放置一个简单的shell脚本文件来测试它,并使用和不使用其绝对位置调用它来查看是否得到相同的差异。