2010-08-19 11 views

Antwort

174
timing = Benchmark.measure { Post.all } 

Die verschiedenen Attribute des Objekts zurück (Benchmark :: Tms) sind here vorgesehen.

+22

auch 'Benchmark.ms {Post.All}' – Bohdan

+0

nice) Danke Jungs – rusllonrails

+5

Ich habe diesen Beitrag sehr nützlich gefunden: http://caseyscarborough.com/blog/ 2013/07/22/benchmarking-your-ruby-code/ – hernanvicente

1

Mit benchmark-ips gem:

2.3.0 :001 > require 'benchmark/ips' 
=> true 
2.3.0 :002 > Benchmark.ips do |x| 
2.3.0 :003 >  x.report("add: ")  { 1+2 } 
2.3.0 :004?>  x.report("div: ") {1/2} 
2.3.0 :005?>  x.report("iis: ") {1/2.0} 
2.3.0 :006?> end 
Warming up -------------------------------------- 
      add: 280.299k i/100ms 
      div: 278.189k i/100ms 
      iis: 266.526k i/100ms 
Calculating ------------------------------------- 
      add:  11.381M (± 4.5%) i/s -  56.901M in 5.010669s 
      div:  9.879M (± 4.6%) i/s -  49.518M in 5.024084s 
      iis:  9.289M (± 4.2%) i/s -  46.376M in 5.001639s 
Verwandte Themen