fasterer, 不要让红宝石 go

分享于 

4分钟阅读

GitHub

  繁體 雙語
  • 源代码名称:fasterer
  • 源代码网址:http://www.github.com/DamirSvrtan/fasterer
  • fasterer源代码文档
  • fasterer源代码下载
  • Git URL:
    git://www.github.com/DamirSvrtan/fasterer.git
    Git Clone代码到本地:
    git clone http://www.github.com/DamirSvrtan/fasterer
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/DamirSvrtan/fasterer
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    

    Build StatusCode ClimateGem VersionTest CoverageDependency Status

    Fasterer

    Make,Rubies,Rubies,,sferik,,talk。

    Fasterer将建议一些速度改进,你可以在快速 ruby repo 中详细查看。

    请注意,你不应该盲目地遵循建议。 如果你正在执行常规的项目,而不是使用 each_with_index,则不应该考虑使用while循环,但是如果你正在做一些速度依赖的事情,那么你可能会考虑这样的速度,或者你正在构建自己的框架。

    安装

    gem install fasterer

    用法

    从你的项目的root 中运行它:

    fasterer

    示例输出

    
    app/models/post.rb
    
    
    Array#select.first is slower than Array#detect. Occurred at lines: 57, 61.
    
    
    
    db/seeds/cities.rb
    
    
    Hash#keys.each is slower than Hash#each_key. Occurred at lines: 15, 33.
    
    
    
    test/options_test.rb
    
    
    Hash#merge! with one argument is slower than Hash#[]. Occurred at lines: 84.
    
    
    
    test/module_test.rb
    
    
    Don't rescue NoMethodError, rather check with respond_to?. Occurred at lines: 272.
    
    
    
    spec/cache/mem_cache_store_spec.rb
    
    
    Use tr instead of gsub when grepping plain strings. Occurred at lines: 161.
    
    
    
    

    配置

    配置是通过在项目的root 中放置的。fasterer。 文件完成的。

    选项:

    • 关闭速度建议
    • 黑名单文件或者完整文件夹路径

    例如:

    speedups:
     rescue_vs_respond_to: truemodule_eval: trueshuffle_first_vs_sample: truefor_loop_vs_each: trueeach_with_index_vs_while: falsemap_flatten_vs_flat_map: truereverse_each_vs_reverse_each: trueselect_first_vs_detect: truesort_vs_sort_by: truefetch_with_argument_vs_block: truekeys_each_vs_each_key: truehash_merge_bang_vs_hash_brackets: trueblock_vs_symbol_to_proc: trueproc_call_vs_yield: truegsub_vs_tr: trueselect_last_vs_reverse_detect: truegetter_vs_attr_reader: truesetter_vs_attr_writer: trueexclude_paths:
     - 'vendor/**/*.rb' - 'db/schema.rb'

    加速待办事项:

    • 查找 vs bsearch
    • Array#count vs Array#size
    • Enumerable#each + 推 vs Enumerable#map
    • Hash#merge vs Hash#merge !
    • String#casecmp vs String#downcase + = =
    • 字符串连接
    • String#match vs String#start_with/string#end_with?
    • String#gsub vs String#sub

    • fork ( https://github.com/DamirSvrtan/fasterer/fork )
    • 创建你的特征分支( git checkout -b my-new-feature )
    • 提交你的更改( git commit -am 'Add some feature' )
    • 推送到分支( git push origin my-new-feature )
    • 创建新的拉请求