Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 安装的gem比源代码慢得多_Ruby_Rubygems_Rvm - Fatal编程技术网

Ruby 安装的gem比源代码慢得多

Ruby 安装的gem比源代码慢得多,ruby,rubygems,rvm,Ruby,Rubygems,Rvm,运行已安装的gem要比运行本地源代码的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,还是这是Ruby gem

运行已安装的gem要比运行本地源代码的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,还是这是Ruby gems的一个“特性”?有没有办法加快速度

这是生成的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)

只要设置了rvmruby,RVM就会在路径中为您的Ruby版本和gemset放置适当的目录。我的道路是这样开始的:

/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本身。您可以将一个简单的shell脚本文件放在gembin目录中进行测试,并调用它的绝对位置和不调用它的绝对位置,以查看是否有相同的差异。

我确信RVM在计算您当前的ruby版本、定位二进制文件并执行它时会有一些开销。为什么不将bash_配置文件中的alias
wmctile
添加到源代码中呢?它是一个分布式的gem,供其他用户使用,只有gem,没有源代码。@jesselaff它是纯ruby。问题似乎出在生成的文件中,
/usr/bin/env ruby\u executable\u hooks
似乎相当慢。我已经用生成的bin文件的来源编辑了答案。杀毒软件可能是罪魁祸首吗?我见过Ruby和它的gems在运行TrendMicro AV的Windows计算机上明显变慢了。@RuiMarques不,输出来自Ubuntu。我认为这是有道理的。可能是长路径搜索造成的。