I am trying to figure out the efficiency of my server side code.
Using microtime(true)
to measure speed, I am able to calculate the time it took my script to run.
I am getting average speeds of .3
to .5
seconds. These scripts do a number of database queries to return different values to the user.
What is considered an efficient execution time for PHP scripts that will be run online for a website?
I know it depends on exactly what is being done, but just consider this a standard script that reads from a database and returns values to the user. I look at Google and see them search the internet in .15
seconds and I feel like my script is crap.
Assuming each query is returns only a few rows from a couple of tables you should be aiming for execution times nearer to 10 milliseconds that 100ms each.
A long SQL query is really a collection of blocks of code, which are much easier to control and to check for mistakes. Building your query a step at a time is a best practice for SQL development.
The execution time or CPU time, which we call Ci, is the total amount of time that the process executes; that time is generally independent of the initiation time but often depends on the input data. We often define deadlines for periodic processes, but we may also want to define a deadline for an aperiodic process.
The slow query log consists of SQL statements that take more than long_query_time seconds to execute and require at least min_examined_row_limit rows to be examined. The slow query log can be used to find queries that take a long time to execute and are therefore candidates for optimization.
YouTube's target page rendering time is < 100ms (Video here @7:00).
Your bottleneck is probably DB queries - try using
EXPLAIN select * from x...
to see if you can add indexes that will speed up your queries.
edit the link above has died. High Scalability did a feature on YouTube that used that video as its primary source, so it may be of some interest: http://highscalability.com/youtube-architecture
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With