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.


Thank you for posting a comment

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
How to no-mincss links with django-pipeline 03 February 2016
Django forms and making datetime inputs localized 04 December 2015
mozjpeg installation and sample 10 October 2015
Examples of mozjpeg savings 01 September 2015
Introducing optisorl 18 August 2015
How do log ALL PostgresSQL SQL happening 20 July 2015
Python slow-down of exception handling or condition checking 14 May 2015
Benchmarking Autocompeter 12 April 2015
AJAX or not 22 December 2014
Gzip rules the world of optimization, often 09 August 2014