Your Ad Here
27th
April

Choosing Optimal MySQL Data Types

It is too often that developers use the wrong data types in their databases. As queries to databases take a major amount of time in any application, it is essential that the database and its tables are as optimised as possible to ensure the best efficiency, especially in high-demand applications. Read more »

16th
February

Tips for Faster JavaScript Scripts

So, after a reasonably successful "Tips for Faster PHP Scripts" series, I've thought about what else I could write about. As I've been using JavaScript quite a lot recently, I decided to write about ways to improve scripts so they run faster.

It is important than JavaScript scripts are fast, because you can not determine the execution speed on the wide range of clients' browsers.

You can not also determine how fast peoples' internet connections are, so it is important that the scripts get to the clients' browsers as fast as possible.

Some of these tips may not be entirely practical and may make the scripts harder to maintain, but I believe there should be compromise between making maintainable code and speed- and resource- efficient code.

1. Combining Scripts to One File

When Javascript files are requested, the server sends a few headers. Sometimes these headers can take more bytes than actual JavaScript itself.

For example, if 5 single JavaScript files are requested, they each will be received like this (with headers shown):

HTTP/1.1 200 OK
Date: Sat, 16 Feb 2008 18:55:10 GMT
Server: Apache/2.2.4 (Win32) mod_ssl/2.2.3 OpenSSL/0.9.8d PHP/5.2.1
Last-Modified: Sat, 16 Feb 2008 18:55:08 GMT
ETag: "6d37-86-fd04022"
Accept-Ranges: bytes
Content-Length: 134
Connection: close
Content-Type: application/x-javascript

function aFunctionName(arg1, arg2) {
if(arg1 == arg2)
return 0;
if(arg1 < arg2)
return -1;
if(arg1 > arg2)
return 2;
}

The total size of this transmission, including headers, is 424 bytes. The code itself is just 125 bytes. If similar code was loaded 5 times, the total size of the transmissions will be 2120 bytes. If, though, all the code was put into one file, the size of transmission would be 933 bytes, a saving of about 56%.
Read more »

27th
November

Even More Tips for faster PHP scripts

Following on from "Tips for faster PHP Scripts" and "More Tips for Faster PHP Scripts", I bring you Even More Tips for faster PHP Scripts.

Because I've already talked about the main, general, optimization tips, these ones will tend to be more specific and may not apply to everyone - nonetheless, it's worth a read in case you ever do come across these situations.

Here are tips 11-15:

11. is_numeric() vs. ctype_digit()
To see whether is_numeric() or ctype_digit() is the fastest method, I called each function 10,000,000 times. Here are the resuts:

is_numeric(): 9.943268 seconds
ctype_digit(): 11.801991 seconds
is_numeric() is 15.75% faster than ctype_digit()

It's worth using is_numeric() over ctype_digit() where it's appropriate to do so. Although a difference of 0.0000001858723 may seem small, it does all add up.
Read more »