简体   繁体   English

基准测试Rails模型方法

[英]Benchmarking Rails Model Methods

Is there something similar to Ruby Benchmark within Rails? 在Rails中有类似于Ruby Benchmark的东西吗? I have used Ruby benchmark in the past to compare different bits of code, but none of it was Rails related. 我过去曾使用Ruby基准来比较不同的代码,但没有一个是与Rails相关的。 I would like to use my application models in some benchmarking to do something along the lines of... 我想在一些基准测试中使用我的应用程序模型来做某些事情......

#!/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

Which gives me some output like this: 这给了我一些像这样的输出:

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)

I looked into script/performance/benchmarker and script/performance/profiler, but I couldn't figure out a way to compare methods. 我查看了脚本/性能/基准测试程序和脚本/性能/分析器,但我无法找到比较方法的方法。 I also looked into doing it within a test, but I don't have any sort of assertions, so that didn't seem to make sense. 我也考虑过在测试中做这件事,但我没有任何断言,所以这似乎没有意义。

Performance testing your rails application might be all you need. 可能只需要对rails应用程序进行性能测试 I think that's all you can do with standalone Rails. 我认为这就是你可以用独立的Rails做的一切。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM