代码之家  ›  专栏  ›  技术社区  ›  Peter Brown

基准化rails模型方法

  •  6
  • Peter Brown  · 技术社区  · 15 年前

    rails中是否有类似于ruby基准测试的东西?我过去曾使用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
    

    给了我这样的输出:

    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)
    

    我研究了script/performance/benchmarker和script/performance/profiler,但是我没有找到比较方法的方法。我也研究了在测试中做这件事,但我没有任何断言,所以这似乎没有意义。

    1 回复  |  直到 9 年前
        1
  •  5
  •   AnkitG    11 年前

    Performance testing your rails application 可能是你所需要的。我认为这就是独立rails所能做的一切。