2009 m. lapkričio 28 d., šeštadienis

Blueprints VS. Factory Girl: speed comparison

Introduction

Last saturday I wrote an introduction to my new gem Blueprints. You might want to read it before reading this. Today I wanted to compare the performance of them.

Spec file

I wrote 5 almost identical spec files. You can find them here. Basically what they do is create two animals (tiger and bunny) and check animal count + check each attribute for each animal. Since factory girl doesn't support any kind of cleanup after tests (I suppose it trusts the good will of fixtures) and I wasn't doing rails project, I had to emulate transactions being created and rolled back. I've also tried simply deleting all records after each test to compare performance.

Tests

SuiteBest timeWorst time
Factory girl0.897s1.058s
Factory girl (non transactional)1.332s1.537s
Blueprints0.870s0.992s
Blueprints (with preloaded)0.750s0.877s
Blueprints (with preloaded) x 100.824s0.879s


Explanations

Best time is the best time result that `time` has reported to me, worst time is worst.
Non transactional means that test didn't use transactions (all records were simply deleted after each test).
With prebuilt means that fixture data was prebuilt and saved in database (not rebuilt before every test)
x 10 means that all tests were performed 10 times.

Conclusion

Raw performance between blueprints and factory girl don't really differ, as 90% of work has to be done by database. You probably also noticed that being transactional means 50% more speed. What's more interesting is tests with prebuilt data. 70 tests with same data ran pretty much the as long 7 tests. This means you can save huge amounts of time by prebuilding data that is often used throughout tests. I've already mentioned in my last post how in one project we started prebuilding data for two users and tests started passing twice faster. For an average project that could mean instead of waiting 10 minutes for tests to finish it would only take 5! Don't you hate sitting and watching those dots?

Komentarų nėra: