Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Performance benchmarking using RSPec

Tags:

I'm just coming across to RSpec from rake:test, and I'm struggling to find any equivalent to rake test:benchmark and/or rake test:profile.

So, what do most rspec folks use for performance testing? I've found --profile, which spits back the ten slowest tests, but I was hoping for something a little more comprehensive.

Cheers...

like image 395
PlankTon Avatar asked Jan 25 '11 00:01

PlankTon


2 Answers

The Diaspora project took an interesting approach to performance testing with rspec -- tests that say "this method should be fast / take less than N ms"

https://github.com/diaspora/diaspora/blob/a6f8b2c14ed7ec13f2ecd113ae809a072814ab50/spec/controllers/aspects_controller_spec.rb#L92

Different than the typical approach but implementable without any half-baked rspec plugins

like image 160
jamiew Avatar answered Sep 25 '22 19:09

jamiew


There is rspec-benchmark ruby gem which allows to test the performance in the clean and readable way:

expect { ... }.to perform_under(0.01).sec

You can also specify the number of times to run your code to measure performance:

expect { ... }.to perform_under(0.01).and_sample(10)
like image 20
Hirurg103 Avatar answered Sep 23 '22 19:09

Hirurg103