Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance between Django and raw Python

Tags:

python

django

I was wondering what the performance difference is between using plain python files to make web pages and using Django. I was just wondering if there was a significant difference between the two. Thanks

like image 216
vt-cwalker Avatar asked Mar 06 '11 02:03

vt-cwalker


People also ask

Which is better Python or Django?

Python has a set of language and object-oriented approach that helps programmers create clear and logical code. Django is a web development python framework that makes it easy to build powerful web applications. The platform comes with useful built-in features found at the Django Admin Interface.

Is Django fast Python?

Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel. It's free and open source. Ridiculously fast.

What is faster Flask or Django?

Lightweight frameworks often outperform larger frameworks. Because of their size, speed is a natural perk. In essence, this means Flask is faster than Django, though the difference is negligible. Both frameworks are deployed on high-traffic websites.

What is better than Django?

Flask is considered more “Pythonic” than Django is basically since Flask web application code is, in most cases, more unequivocal. Flask is the choice of most tenderfoots due to the need of barricades to getting a basic app up and running.


1 Answers

Django IS plain Python. So the execution time of each like statement or expression will be the same. What needs to be understood, is that many many components are put together to offer several advantages when developing for the web:

  • Removal of common tasks into libraries (auth, data access, templating, routing)
  • Correctness of algorithms (cookies/sessions, crypto)
  • Decreased custom code (due to libraries) which directly influences bug count, dev time etc
  • Following conventions leads to improved team work, and the ability to understand code
  • Plug-ability; Create or find new functionality blocks that can be used with minimal integration cost
  • Documentation and help; many people understand the tech and are able to help (StackOverflow?)

Now, if you were to write your own site from scratch, you'd need to implement at least several components yourself. You also lose most of the above benefits unless you spend an extraordinary amount of time developing your site. Django, and other web frameworks for every other language, are designed to provide the common stuff, and let you get straight to work on business requirements.

If you ever banged out custom session code and data access code in PHP before the rise of web frameworks, you won't even think of the performance cost associated with a framework that makes your job interesting and eas(y)ier.

Now, that said, Django ships with a LOT of components. It is designed in such a way that most of the time, they won't affect you. Still, a surprising amount of code is executed for each request. If you build out a site with Django, and the performance just doesn't cut it, you can feel free to remove all the bits you don't need. Or, you can use a 'slim' python framework.

Really, just use Django. It is quite awesome. It powers many sites millions times larger than anything you (or I) will build. There are ways to improve performance significantly, like utilizing caching, rather than optimizing a loop over custom Middleware.

like image 97
Josh Smeaton Avatar answered Oct 17 '22 01:10

Josh Smeaton