[web] Which one is more efficient? JSP or PHP

Started by
19 comments, last by chollida1 17 years, 9 months ago
Quote:Original post by Spoonbender
Quote:Original post by mfk_1868
By this way I am thinking of minimizing the database query number to minimum. Is this a good idea?

Yep, that's pretty much rule #1 in database queries. Don't use two queries if you can manage with one. Crossing the boundary from your external application to the database is expensive, so use as few queries as possible.


Not necessarily. In some cases, especially when using GROUP BY, 2 queries will be stupidly faster than one (think 10 minutes vs less than 1 second) I learned this the hard way :/ The number of queries doesn't matter as much as the quality of them.
Advertisement
Out of curiousity.... can you give an example of where 2 queries out preforms the GROUP BY clause?
performance of your server side scripting language is almost entirely irrelivant. who cares if you take 200ms or 250ms to run your code when each database query can take full seconds to complete. the only thing that you really care about optimizing is the number of database queries you make per page load.

-me
do you know a way that we can measure the time of a query?
Quote:Original post by Cygnus_X
Out of curiousity.... can you give an example of where 2 queries out preforms the GROUP BY clause?
In the forum I was developing, I was pulling thread information, number of unique views, and number of unique replies all in the same query. This involved about 12 tables, most of which were only required for the thread information (which of course would be the same for each corresponding view and reply). Splitting the query into 3 (one to pull thread info, one for the number of views, and one for the number of replys) sped things up a great deal (as I said, from around 10 minutes to under one second). In most cases I have encountered, the overhead of sending multiple queries is way less than that of a more complex query involving GROUP BY.

The point is that, when striving for efficiency, there isn't one black-and-white rule. It's like indexes - just because they can make some queries faster doesn't mean you should create one for every single field.
Quote:Original post by mfk_1868
do you know a way that we can measure the time of a query?


Get the microtime before the query. Get it afterwards. Calculate the difference. If you use a database abstraction layer of some sorts then it's quite easy to build a profiler into it.

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

that can be shorter in group by statements which are very complex but I dont think it can be in basic sql statements.

The worst performance statements are join statements in sql. But in general minimizing query number brings performance.

PS: I dont mean joining all tables and getting all data in one query. I mean if you get some data from a table do it in one step instead of a lot.

I fully believe that there is no reason to ever use PHP. It's a toy language that grew far past its original scope and is now a horrid, horrid piece of tripe.

JSP and the whole Java EE thing are not my favorite either, but at least it's a semi-properly structured language.

Give me ASP.NET with C#.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Quote:Original post by capn_midnight
Give me ASP.NET with C#.


No thanks. I prefer not to use MS servers. Perhaps you should give Python a try. I've never used it for webdev before but it's supposed to be quite good.

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

Quote:Original post by Sander
Quote:Original post by capn_midnight
Give me ASP.NET with C#.


No thanks. I prefer not to use MS servers. Perhaps you should give Python a try. I've never used it for webdev before but it's supposed to be quite good.


actually, I've been playing around with Ruby lately (hehe, ever since watching
">this). It's a strange little language, if not a wee bit flaky here and there. I'm primarily interested in the Camping web app framework, I'm interested to see just how featureful it is, considering how "small" (sans dependencies) it is.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

This topic is closed to new replies.

Advertisement