Date formatting in Python or in PostgreSQL (part II)

19 April 2006   0 comments   Python

Mind That Age!

This blog post is 11 years old! Most likely, its content is outdated. Especially if it's technical.

Powered by Fusion×

This is an update on Date formatting in python or in PostgreSQL where the test wasn't done very well. The solution using Python for the formatting created a new DateTime object each time for each formatting because the time_stamp extracted from the database was a string. That would be beneficial to the Python formatting alternative but that's not the whole point. I suspect that the way I did the experiment last time (code is lost by the way) was wrong and didn't focus on the correct benchmark.

In this, my second attempt, I've done a more correct test and tried it on 500 selects. 500 formatted in SQL and 500 formatted in Python. The results are even more outstanding for PostgreSQL than last time.

Here are the results:

times1 (python formatted)
0.113439083099
times2 (sql formatted)
0.00697612762451

That means that doing the date formatting in SQL is 16 times faster!!

Bare in mind that this is optimization and you always have to be careful when doing optimization. For example, the SQL database shouldn't get involved in the presentation and if you need to use a different locale you might to change your application in two places which is risky.

Follow @peterbe on Twitter

Comments

Thank you for posting a comment

Your email will never ever be published


Related posts

Previous:
Careful when dealing with options in IE 14 April 2006
Next:
Best bicycle locks 22 April 2006
Related by Keyword:
Fastest way to match a filename's extension in Python 31 August 2017
Fastest *local* cache backend possible for Django 04 August 2017
How to do performance micro benchmarks in Python 24 June 2017
Don't forget your sets in Python! 10 March 2017
Optimization of QuerySet.get() with or without select_related 03 November 2016
Related by Text:
Date formatting in python or in PostgreSQL 20 July 2004
Speed test between django_mongokit and postgresql_psycopg2 09 March 2010
Fastest "boolean SQL queries" possible with Django 14 January 2011
PostgreSQL, MySQL or SQLite 04 April 2004
Simple or fancy UPSERT in PostgreSQL with Django 11 October 2017