基准测试Rails模型方法

Pet*_*own 6 ruby benchmarking ruby-on-rails

在Rails中有类似于Ruby Benchmark的东西吗?我过去曾使用Ruby基准来比较不同的代码,但没有一个是与Rails相关的.我想在一些基准测试中使用我的应用程序模型来做某些事情......

#!/usr/bin/ruby
require 'benchmark'

Benchmark.bmbm do |x|
  x.report("Benchmark 1") do 
    1_000_000.times do
      # do something here...
    end
  end

  x.report("Benchmark 2") do
    1_000_000.times do
      # Do something else here...
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

这给了我一些像这样的输出:

Rehearsal -----------------------------------------------
Benchmark 1   0.070000   0.000000   0.070000 (  0.069236)
Benchmark 2   0.070000   0.000000   0.070000 (  0.069227)
-------------------------------------- total: 0.140000sec

                  user     system      total        real
Benchmark 1   0.070000   0.000000   0.070000 (  0.069793)
Benchmark 2   0.070000   0.000000   0.070000 (  0.069203)
Run Code Online (Sandbox Code Playgroud)

我查看了脚本/性能/基准测试程序和脚本/性能/分析器,但我无法找到比较方法的方法.我也考虑过在测试中做这件事,但我没有任何断言,所以这似乎没有意义.

Chr*_*ris 5

可能只需要对rails应用程序进行性能测试.我认为这就是你可以用独立的Rails做的一切.