Following on from yesterday's blog about How and why to use django-mongokit I extended the exampleproject which is inside the django-mongokit project with another app called
exampleapp_sql which does the same thing as the
exampleapp but does it with SQL instead. Then I added a very simple benchmarker app in the same project and wrote three functions:
- One to create 10/100/500/1000 instances of my class
- One to edit one field of all 10/100/500/1000 instances
- One to delete each of the 10/100/500/1000 instances
The results can speak for themselves:
# 10 mongokit django_mongokit.mongodb Creating 10 talks took 0.0108649730682 seconds Editing 10 talks took 0.0238521099091 seconds Deleting 10 talks took 0.0241661071777 seconds IN TOTAL 0.058883190155 seconds sql django.db.backends.postgresql_psycopg2 Creating 10 talks took 0.0994439125061 seconds Editing 10 talks took 0.088721036911 seconds Deleting 10 talks took 0.0888710021973 seconds IN TOTAL 0.277035951614 seconds # 100 mongokit django_mongokit.mongodb Creating 100 talks took 0.114995002747 seconds Editing 100 talks took 0.181537866592 seconds Deleting 100 talks took 0.13414812088 seconds IN TOTAL 0.430680990219 seconds sql django.db.backends.postgresql_psycopg2 Creating 100 talks took 0.856637954712 seconds Editing 100 talks took 1.16229200363 seconds Deleting 100 talks took 0.879518032074 seconds IN TOTAL 2.89844799042 seconds # 500 mongokit django_mongokit.mongodb Creating 500 talks took 0.505300998688 seconds Editing 500 talks took 0.809900999069 seconds Deleting 500 talks took 0.65673494339 seconds IN TOTAL 1.97193694115 seconds sql django.db.backends.postgresql_psycopg2 Creating 500 talks took 4.4399368763 seconds Editing 500 talks took 5.72280597687 seconds Deleting 500 talks took 4.34039878845 seconds IN TOTAL 14.5031416416 seconds # 1000 mongokit django_mongokit.mongodb Creating 1000 talks took 0.957674026489 seconds Editing 1000 talks took 1.60552191734 seconds Deleting 1000 talks took 1.28869891167 seconds IN TOTAL 3.8518948555 seconds sql django.db.backends.postgresql_psycopg2 Creating 1000 talks took 8.57405209541 seconds Editing 1000 talks took 14.8357069492 seconds Deleting 1000 talks took 11.9729249477 seconds IN TOTAL 35.3826839924 seconds
On average, MongoDB is 7 times faster.
All in all it doesn't really mean that much. We expect MongoDB to be faster than PostgreSQL because what it lacks for in features it makes up for in speed. It's interesting to see it in action and nice to see that MongoKit is fast enough to benefit from the database's speed.
As always with benchmarks: Lies, lies and more damn lies! This doesn't really compare apples for apples but hopefully with django-mongokit the comparison is becoming more fair. Also, you're free to fork the project on github and do your optimizations and re-run the tests yourself.