Almost premature optimization

02 January 2015   0 comments   Python, Web development, Django

Powered by Fusion×

In airmozilla the tests almost all derive from one base class whose tearDown deletes the automatically generated settings.MEDIA_ROOT directory and everything in it.

Then there's some code that makes sure a certain thing from the fixtures has a picture uploaded to it.

That means it has do that shutil.rmtree(directory) and that shutil.copy(src, dst) on almost every single test. Some might also not need or depend on it but it's conveninent to put it here.

Anyway, I thought this is all a bit excessive and I could probably optimize that by defining a custom test runner that is first responsible for creating a clean settings.MEDIA_ROOT with the necessary file in it and secondly, when the test suite ends, it deletes the directory.

But before I write that, let's measure how many gazillion milliseconds this is chewing up.

Basically, the tearDown was called 361 times and the _upload_media 281 times. In total, this adds to a whopping total of 0.21 seconds! (of the total of 69.133 seconds it takes to run the whole thing).

I think I'll cancel that optimization idea. Doing some light shutil operations are dirt cheap.


Thank you for posting a comment

Your email will never ever be published

Related posts

AJAX or not 22 December 2014
My favorite Go multiplexer 28 January 2015
Related by Keyword:
Cryptic errors when using django-nose 07 December 2011
Test static resources in Django tests 02 June 2011
Related by Text:
Speed test between django_mongokit and postgresql_psycopg2 09 March 2010
All your images are belong to data uris 06 January 2013
More CSS load performance experiments (of a React app) 25 March 2017
Examples of mozjpeg savings 01 September 2015
Mozilla Symbol Server (aka. Tecken) load testing 06 September 2017