Posts Tagged ‘environment’

JavaScript vs Java

Wednesday, July 16th, 2008

Although the names are much alike, JavaScript is primarily a scripting language for use within HTML pages, while Java is a real programming language that does quite different things from JavaScript. In addition Java is much harder to learn. It was developed by Sun for use in pretty much anything that needs some computing power.

JavaScript was developed by Brendan Eich, then working at Netscape, as a client side scripting language (even though there’s no fundamental reason why it can’t be used in a server side environment).

Originally the language was called Live Script, but when it was about to be released Java had become immensely popular (and slightly hypey). At the last possible moment Netscape changed the name of its scripting language to “JavaScript”. This was done purely for marketing reasons. Worse, Eich was ordered to “make it look like Java”. This has given rise to the idea that JavaScript is a “dumbed-down” version of Java. Unfortunately there’s not the slightest shred of truth in this story.

Java and JavaScript both descend from C and C++, but the languages (or rather, their ancestors) have gone in quite different directions. You can see them as distantly related cousins. Both are object oriented (though this is less important in JavaScript than in many other languages) and they share some syntax, but the differences are more important than the similarities.

If you are a C++ or Java programmer you will be surprised by some of JavaScript’s features. Since I don’t have any previous programming experience, the differences are not described on this site. The best you can do is buy David Flanagan, “JavaScript, the Definitive Guide”, 5th edition, O’Reilly, 2006. In this book the differences between C++/Java and JavaScript are clearly explained. I co–edited a few chapters of this book.

7 tips for lightning fast PHP sites

Saturday, June 28th, 2008

1. sizeof vs count

First up are the sizeof and count functions. They can both be used to count the number of items in an array but does one do it better?

sizeof vs count
sizeof: 3.75928902626 seconds
count: 3.33035206795 seconds
Time saved: 0.428936958313 seconds; 12.8796280262%

The evidence says yes. The count function was over 12% faster in this test. Both functions are fast though taking 3-4 microseconds to count an array with 100,000 items. You might think it isn’t worth it but remember count is also a character shorter. Not only is it faster to run but it is also faster to type!

2. is_int vs is_integer

Next it is time to try some validation with is_int and is_integer.

is_int vs is_integer
is_int: 3.11394786835 seconds
is_integer: 3.42630600929 seconds
Time saved: 0.312358140945 seconds; 9.11646946006%

The difference is smaller this time but again both functions are executing in a little over 3 microseconds. is_int is faster than is_integer so again the shorter function name wins. Is this going to be a pattern?

3. chop vs rtrim

Tidying up a string breaks the pattern. Maybe my analysis was a little premature.

chop vs rtrim
chop: 4.73731994629 seconds
rtrim: 4.41647195816 seconds
Time saved: 0.320847988129 seconds; 7.26480301852%

rtrim is a little faster and these functions take longer at a little over 4 microseconds.

4. doubleval vs floatval

Both these functions allow you to quickly pick a float, or double, out of a string.

doubleval vs floatval
doubleval: 4.56571412086 seconds
floatval: 4.35375285149 seconds
Time saved: 0.211961269379 seconds; 4.8684727087%

4% or 211 nanoseconds is next to nothing. I would want to use floatval but I wouldn’t exactly be kicking myself if I slipped a doubleval into my code instead.

5. fwrite vs fputs

So far all the functions have been running fast anyway so the difference haven’t been that significant but things are starting to get interesting with the run time jumping to 20-24 microseconds to write a short string to a file.

fwrite vs fputs
fwrite: 24.9826359749 seconds
fputs: 20.1990799904 seconds
Time saved: 4.7835559845 seconds; 23.6820488199%

With a difference of over 4 microseconds you could run both fputs and floatval in the time it takes to run fwrite. The difference is over 23% which clearly makes fputs the better function. It’s shorter as well.

6. implode vs join

This one really surprised me. I expected these functions to be faster. Both these functions allow you to convert an array into a string. implode is the opposite of explode and join allows you to join the items in an array with a ‘glue’ string. In this case the array had 100 items.

implode vs join
implode: 47.2712550163 seconds
join: 50.1287050247 seconds
Time saved: 2.85745000839 seconds; 5.70022705949%

5% doesn’t seem like all that much but 2 microseconds shouldn’t be ignored.

7. ini_alter vs ini_set

Finally lets look at modifying the environment. I actually cheated here and just set the max execution time to 60 seconds a million times. I think the result is still valid though

ini_alter vs ini_set
ini_alter: 103.332370043 seconds
ini_set: 86.2883789539 seconds
Time saved: 17.0439910889 seconds; 19.7523598143%

As might be expected these functions are expensive when it comes to execution time. That 17 microsecond saving is massive as well making ini_set the superior choice.

Speedy sites

PHP has a vast array of functions enabling a large variety of tasks to be performed without the programmer ‘reinventing the wheel’. These functions are not all created equal though and real speed boosts can be achieved by choosing the right functions.
v

Firefox:Platform-Native Look & Feel

Friday, June 27th, 2008

The new Firefox looks and feels like home. Think of it as a Firefox who’s really good at making friends. Whether you use Windows Vista, Windows XP, Mac or Linux, the browser seamlessly integrates into your computer’s environment. A native look makes for a flawless interface that never gives you pause.

Virtual Private Server (VPS) Web Hosting

Thursday, June 26th, 2008

Shared hosting allows thousands of people to host their own sites at a very reasonable cost. It has some drawbacks, however. Since hundreds of sites can be hosted on a single server resources such as CPU, disk space, and bandwidth have to be shared with your virtual neighbours.

Shared resources are usually not a problem for small to medium sized sites. Your main limitation is the lack of control over system level software – http servers, mail servers etc. You don’t have any choice of operating system and you cannot compile programs or do administrative tasks such as setting up Spam filters or firewalls.

Many people would say ‘So what? I don’t want to do that stuff anyway!’ It’s true that the majority of website owners have no interest or ability to handle this kind of work and are happy to leave it to the hosting company. Those who desire more control over their server environment or wish to experiment with new software, however, can get access to this level of management with a Virtual Private Server.

A virtual private server (VPS) is a physical server that has been divided (using software) into several virtual machines, each acting as an independent dedicated server. The physical resources such as RAM, CPU and disk space are still shared, but each VPS acts independently of the others. Each VPS can have a different operating system and can be configured in any way possible.

The key advantage of VPS is allowing each VPS administrator access to the root level of his virtual server. This kind of access allows the administrator to install and delete software, set permissions, create accounts – in short, do everything that the administrator of a ‘real’ sever can.

As well as providing more control over your hosting environment, a VPS is more secure than shared hosting. Websites on a shared server all have the same operating system, so if a hacker were to find access to the root of the server he could damage any or all of the websites on that server. A VPS, on the other hand, is divided in such a way that even if a hacker were to gain entry through one account, there is no way to access the others. Each VPS is invisible to the others and there is no way to set up root level access from one VPS to another.

Virtual Private Servers can be set up in various ways so be sure to understand how the hosting company has allocated resources. The most common configuration is to divide all the physical resources evenly by the number of accounts. Thus, if there are 10 virtual servers, each would receive 10% of the total bandwidth, CPU, memory and disk space.

The disadvantages of VPS are almost the same as the advantages. The control that a VPS account provides can be dangerous if you don’t know what you are doing. You have the ability to delete files, set permissions improperly, allow virus-laden software on the system and, in general, really screw things up. If you don’t have the knowledge to administer a server, or are not willing to learn, VPS is not for you.

If your website has outgrown shared hosting, however, VPS offers an affordable alternative to dedicated hosting. When shopping for a VPS host, be sure to find out how system resources are divided up, the number of VPS accounts on each physical server, the method for upgrading, and the choices of operating systems.

One step forward: a review of GNOME 2.22

Monday, June 16th, 2008

The latest release of the GNOME desktop environment includes a number of significant architectural enhancements and new applications that offer increased power and usability. Released after six months of intensive development, GNOME 2.22 will be included in Ubuntu 8.04 and Fedora 9, which are scheduled for release in April.