Date formatting in Python or in PostgreSQL (part II)

19 April 2006   0 comments   Python

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)
times2 (sql formatted)

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.


Your email will never ever be published

Related posts

Careful when dealing with options in IE 14 April 2006
Best bicycle locks 22 April 2006
Related by keywords:
Fastest way to uniqify a list in Python 14 August 2006
mincss "Clears the junk out of your CSS" 21 January 2013
Gzip rules the world of optimization, often 09 August 2014
Fastest database for Tornado 09 October 2013
Integer division in programming languages 04 August 2004
Optimization of getting random rows out of a PostgreSQL in Django 23 February 2011
Connecting with psycopg2 without a username and password 24 February 2011
Credit Card formatter in Javascript 19 November 2013
Adding a year in PostgreSQL 04 February 2004
pg_class to check if table exists 20 April 2005
Local Django development with Nginx 11 October 2010
Fastest way to thousands-commafy large numbers in Python/PyPy 13 October 2012