Why is RSpec so slow with Rails 3?

I’m just learning my way through ruby and rails to learn it. One thing
I noticed is that testing 1 spec class with 1 test takes about 20
seconds. It’s not even using any rails functionality at all. I am just
concatenating some strings together and doing some math…

Contrast this with JUnit or ScalaTest… and I could have ran an
entire suit of thousands of tests in this amount of time.

One of the reasons I hated grails (I played with it about a year ago)
was that tests ran rediculously slow, so the test/feedback cycle was
horrendous… and I just refused to put up with that.

People knock Java/Spring/Hibernate, but you can have a fully tiered,
database-driven app that populates 100-150 rows of data per test that
runs 1000+ tests in under 60 seconds.

Given that knowledge… 20 seconds for 1 test that does nothing seems
very, very wrong. Any way I can speed this up?

On Oct 9, 8:32 pm, egervari [email protected] wrote:

horrendous… and I just refused to put up with that.

People knock Java/Spring/Hibernate, but you can have a fully tiered,
database-driven app that populates 100-150 rows of data per test that
runs 1000+ tests in under 60 seconds.

Given that knowledge… 20 seconds for 1 test that does nothing seems
very, very wrong. Any way I can speed this up?

Even in the worst case I’ve experienced it’s been a few seconds of
start-up overhead, nothing close to 20. What versions of rspec and
rails are you using? What command are you using to run the spec? What
OS, ruby version, etc?

Okay, I admit and I newbie when it comes to this stuff. I’m using
Rails 3 (latest) and I put this line in my Gemfile:

group :test do
gem ‘rspec-rails’
end

I’m guessing that’s going to get the latest version of rspec-rails.

As for other questions, I’m running Ruby 1.9.1 on Windows 7 64-bit
(not exactly the best OS for out-of-the-box working and stable use of
Ruby, I know).

In my IDE, If I run the same could out of RSpec, it is basically
instant. If I run RSpec, it reports that the test only took 5 seconds,
but the entire execution was 20 seconds. If I had more dummy tests in
the same Spec file, it is basically instant. So my guess is that 15
seconds is used by Rails and 5 seconds is used by RSpec? My guess is
that the actual code in the tests is a few milliseconds.

I’ll try updating the version of rspec-rails. Thanks for that!

I’m using jetbrans’s rubymine. I’m used to IDEA, so I’m right at home
with RubyMine. I’m using the latest EAP that works with ruby 1.9 and
rails 3.

On Oct 9, 9:29 pm, egervari [email protected] wrote:

Okay, I admit and I newbie when it comes to this stuff. I’m using
Rails 3 (latest) and I put this line in my Gemfile:

group :test do
gem ‘rspec-rails’
end

I’m guessing that’s going to get the latest version of rspec-rails.

Actually that gets the latest production release of rspec-rails, which
is rspec-rails-1.3.3 (as of about 10 minutes ago).

What you want is rspec-rails-2.0.0.rc, and you want to include it in
both development and test groups:

group :development, :test do
gem ‘rspec-rails’, ‘>= 2.0.0.rc’
end

As for other questions, I’m running Ruby 1.9.1 on Windows 7 64-bit
(not exactly the best OS for out-of-the-box working and stable use of
Ruby, I know).

Yeah - I’ve given up trying to run ruby on windows. It’s just so much
better on Linux or Mac OS. There are plenty of people here, more brave
than I, however, who can help you in that area.

In my IDE, If I run the same could out of RSpec, it is basically
instant. If I run RSpec, it reports that the test only took 5 seconds,
but the entire execution was 20 seconds. If I had more dummy tests in
the same Spec file, it is basically instant. So my guess is that 15
seconds is used by Rails and 5 seconds is used by RSpec? My guess is
that the actual code in the tests is a few milliseconds.

5 seconds is painfully long for 1 example. Once you’ve paid the
startup debt (which comes from a combination of rspec, rails,
bundler), it should be < 0.001 seconds for one example unless you’re
connecting to an external service of some sort. Although that’s what
I’m seeing on Mac/Linux. Any Windows users wanna report on the times
you’re seeing?

What IDE are you using?

On 10-10-10 12:19 AM, egervari wrote:

Okay, the newest version of the rspec executes all the tests in 2.873
seconds with a total time of 16.7 seconds. My guess is that this rspec-
rails version saved me ~2 seconds and rails is still eating up 15
seconds.

This is very similar to Grails. 15-20 seconds is absurd. I am a
nitpicker and would just outright refuse to program under such
conditions. LOL :wink:

programming RoR on Win7 is absurd imho :wink:

Maybe if I have a spare hard drive I can install linux? What’s a good
distribution these days for someone that likes user-friendly and good
performance?

I use kubuntu, i love kde, its one of the easier linux to setup has
regular updates, latest version 10.10 is out today!

throw vmware or virtualbox on win7 and install linux to run as a virtual
machine on your win7 (no need to worry about dual boot setup), be up and
running in minutes and be rid of the GUI handcuff mindset!

Oh, before I read this post, I realized Ubuntu had a safe windows
installer. I used it, and I’m running unbuntu right now. Man, it took
like 15 minutes to download/install everything, and it takes like 8
seconds to boot up after it was done. You’d think windows could get a
quad core to boot that fast after so many years of making better
cpus…

Anyway, I know very little linux. Well, that’s not true, I used to use
slackware back in 1995, and I’ve used it off and on, but it’s been
many years.

I’d configuring/making ruby, but it says I don’t have permissions. I
could run it as root of course, but I wonder… where was I supposed
to put the ruby-1.9.2 folder? I know this must sound silly, but I
can’t remember where the ‘goto’ place was for putting source files.
Was it under /usr? I don’t remember. It looks a little different than
it used to.

Anyway, I’ll keep plugging away on this end.

Yay, i discovered this program called rvm and now I can get 1.9.2
installed :wink: Woot!

Okay, the newest version of the rspec executes all the tests in 2.873
seconds with a total time of 16.7 seconds. My guess is that this rspec-
rails version saved me ~2 seconds and rails is still eating up 15
seconds.

This is very similar to Grails. 15-20 seconds is absurd. I am a
nitpicker and would just outright refuse to program under such
conditions. LOL :wink:

Maybe if I have a spare hard drive I can install linux? What’s a good
distribution these days for someone that likes user-friendly and good
performance?

Ken

On 10-10-10 02:21 AM, egervari wrote:

Oh, before I read this post, I realized Ubuntu had a safe windows
installer. I used it, and I’m running unbuntu right now. Man, it took
like 15 minutes to download/install everything, and it takes like 8
seconds to boot up after it was done. You’d think windows could get a
quad core to boot that fast after so many years of making better
cpus…

Anyway, I know very little linux. Well, that’s not true, I used to use
slackware back in 1995, and I’ve used it off and on, but it’s been
many years.

you sound like me when I got going =P

use sudo to execute command as root, you will need to enter root
password once, you can download software and place it under /opt (i like
to put things there)

here is what you will need to get up and running, the following will
install the build tools and header files you will need to get Ruby &
Rails build from source.

sudo aptitude install build-essential make
sudo aptitude install libc6-dev libssl-dev
sudo aptitude install libreadline6-dev zlib1g-dev libsqlite3-dev

cd /opt

sudo wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz
sudo tar xvzf ruby-1.9.2-p0.tar.gz

cd ruby-1.9.2-p0

sudo ./configure
sudo make
sudo make test
sudo make install

verify you have ruby, gem, irb installed

ruby -v
gem -v
irb -v

now you’re ready to install rails

sudo gem install rails
sudo gem install sqlite3-ruby

verify you have rails 3.0.0

rails -v

fyi to keep your ubuntu system up to date type

sudo aptitude update
sudo aptitude safe-upgrade

install other gems you need likewise
quick way to search for gems on a keyword such as ‘debug’ below:

sudo gem search debug --remote

happy hacking =)


Kind Regards,
Rajinder Y.

Ok, well I’m up and running anyway. The entire round trip to run my
specs is 3 seconds. RSpec reported that it only took 0.017264579
seconds to run the same test.

LOL.

Either my windows installation (which isn’t that old) has massive
entropy going on when it comes to installed software and what not…
or windows 7 64-bit is an utter piece of crap.

One question though… RubyMine runs really, really bad. I could only
install the OpenJDK and not the Sun JDK… and JetBrains says it’s
going to run bad when you load the IDE.

Is there a sexy-looking, sexy-functioning IDE out there for Linux/
Ubuntu? Something with code colouring (the rails cast colouring is
very nice), refactoring, having it suggests stuff as you type (like
“.” to call method on an object) and stuff like that?

The only ones that come to mind are netbeans or eclipse, but maybe
there’s other ones?

Wow, I had no idea you wrote all that stuff. I posted I got it working
before your post :wink:

Yeah, I actually did much of this stuff on my end, so I’m glad to see
verification that I was doing things right! :wink: I had problems using
“bundle install” with sqlite, so yeah, I had to install those 2
sqlite3 packages. Lousy error messages though. Good thing google
exists! :wink:

I think the last thing left is to either figure out a way to get the
openjdk to run well with rubymine, or find another ide. I really like
jetbrains’ products. I’ve used intellij idea for almost 10 years and
love it, so having that same experience would be great (not to mention
I don’t have to learn any new keyboard shortcuts and get confused as I
continue to work on my java projects).

On 10-10-10 02:57 AM, egervari wrote:

Yay, i discovered this program called rvm and now I can get 1.9.2
installed :wink: Woot!

you don’t need RVM, follow my instruction in the other email and you
will be working with the latest & greatest!


Kind Regards,
Rajinder Y.

On 10-10-10 03:29 AM, egervari wrote:

Is there a sexy-looking, sexy-functioning IDE out there for Linux/
Ubuntu? Something with code colouring (the rails cast colouring is
very nice), refactoring, having it suggests stuff as you type (like
“.” to call method on an object) and stuff like that?

The only ones that come to mind are netbeans or eclipse, but maybe
there’s other ones?

netbeans is a good free choice, but i like to use kate a super fast,
lightweight editor, syntax highlighting, can open a small terminal
screen and have a folder view, what more can you want then the power of
the command line dude! =P

seriously you don’t need all that other stuff, it gets in the way and
makes you lazy imho!

$ aptitude search sun | grep java
p sun-javadb-client - Java DB client
p sun-javadb-common - Java DB common files
p sun-javadb-core -Java DB core
p sun-javadb-demo -Java DB demo
p sun-javadb-doc -Java DB documentation
p sun-javadb-javadoc -Java DB javadoc

try the following to see if rubymine will run faster, you might have to
make it search for the new sun jre

sudo aptitude install sun-javadb-core sun-javadb-common


Kind Regards,
Rajinder Y.

I updated my video card drivers and that seemed to make it go quite a
bit faster. It’s still a bit sluggish at times because of the jdk, but
it’s tolerable. I’ll run with this for now since I’m used to it. I
also don’t think it makes me lazy :wink: It lets me focus on the things
that matter. Maybe it’s different in ruby, but I can not imagine not
using IDEA for java, even if the syntax was nicer.

On 10-10-10 03:49 AM, Rajinder Y. wrote:

make it search for the new sun jre

sudo aptitude install sun-javadb-core sun-javadb-common

ok forget the java stuff above, didn’t notice it was the java db stuff
=P


Kind Regards,
Rajinder Y.

One thing I’ve run into, on a windows box at work, was my ‘home’
directory was a mapped drive on another server on the network. It
took, and I timed this so I wouldn’t exaggerate, 13 minutes to run!
When I moved everything locally it took 45 seconds. I had to change a
start up script so it put my ‘home’ on my c drive.

Cheers,
John I.

On Oct 10, 8:54 am, Hassan S. [email protected]

On Sun, Oct 10, 2010 at 12:40 AM, egervari [email protected]
wrote:

I think the last thing left is to either figure out a way to get the
openjdk to run well with rubymine, or find another ide.

Why don’t you just install the Sun JDK?


Hassan S. ------------------------ [email protected]
twitter: @hassan