I use Subversion on a daily basis, and Mercurial a few days a week. I have noticed that Mercurial seems to be faster with a lot of common operations, but I figured it wasn’t a fair comparison as Mercurial was always operating locally, while Subversion has to hit the network for many (but certainly not all) operations.
So I decided to do some very rough performance comparisons on a local repository. And after some quick timings of common operations, this is what I found… (Updated: fixed table and added graph.)
This is a very rough, and thus not very rigourous evaluation. I performed all tests on a PowerBook G4 1GHz running Mac OS X 10.5 under the same operating conditions (ie. on the train home from work). The versions used:
- Subversion 1.4.4
- Mercurial 0.9.5 with Python 2.5
I created both repositories locally (under
/tmp) and performed the equivalent operations with both VC systems. The source tree used was a recent version of the Django source tree, which is fairly large (2263 files, 568 dirs, 18Mb). For the
svn import equivalent, I did an
hg commit -A of the source tree. For the
svn checkout equivalent, I did an
hg clone of the tree. For the non-mutating operations (eg.
status) I ran the same command 5 times and picked the best.
I tried to be as fair as possible, but not take days to actually come up with some figures. So without further ado…
All times as reported by the
bash time command, taking the real time value (ie. elapsed system time):
|Create Repository||0.346s||0.279s||svn 1.2X|
|Import source tree||12.241s||1m3.781s||hg 5.2X|
|Status (1 mod)||0.631s||0.265s||svn 2.4X|
|Diff (1 mod)||0.778s||0.212s||svn 3.7X|
|Diff (2 mods)||0.784s||0.331s||svn 2.4X|
|Commit (2 mods)||1.164s||3.442s||hg 3.0X|
|Add file||0.544s||0.121s||svn 4.5X|
A simple count of which is faster for each operation shows both scored 5/10, so in that sense they are evenly matched. But in the cases where Subversion was faster, the times were still well under 1sec, so the difference is far less noticeable. It is clear from the above that for many expensive operations, Mercurial is significantly faster than Subversion, even for large I/O operations such as commits and importing. Given Mercurial is written in Python (apart from one small module IIRC), and Subversion is compiled C, this is all the more impressive. Looking at the overall total times for the test workload, Mercurial comes out at 3.6 times faster than Subversion. If you are spending a lot of time with your VC system, this can make a huge difference to your workday productivity.
Clearly the build-in diff engine in Subversion gives it a major advantage in diffs, a very important and common operation. Mercurial is still competitive, and in real-world tests seem to scale well. Having tested it at work with an even larger source tree (the Boost++ library), Mercurial actually seemed to be faster than Subversion for status operations in particular (around a second versus several seconds).
It should be noted that since running Subversion from a local repository like this is the exception rather than the norm for most projects, the performance advantage it has thanks to its fast diff engine evaporates against network latency. Thus using a distributed VCS such as Mercurial can be a great productivity boost, as you only pay for the network when you need to branch or merge between developers, a far less common operation.
This comparison has reinforced my positive impressions of Mercurial, and I hope it serves to bolster peoples’ confidence in its ability to scale and perform. It has all the features of Subversion, plus many more groovy features like patch queues (which I may blog about one day). Since Mercurial is less well known, I hope more people will give Mercurial a try.