09 March 2007

WebDev Performance Tests -- Everybody Wins !

Dave Dash at Spindrop wrote an article about results of a PHP performance test: single versus double quotes. Which method to use is age-old discussion that has plagued PHP developers since they read their first tutorial.

Dave ran three different tests 2 million times each: double-quote concatenation ("test " . $i), double-quote inclusive ("test $i"), and single-quote Concatenation ('test ' . $i). The results were as follows:

double-quote concat:     2.898087978363
double-quote inclusive:  3.5480048656464
single-quote concat:     2.8503499031067
To put that into perspective, here are the average times for each individual operation:
double-quote concat:     0.000001449
double-quote inclusive:  0.000001774
single-quote concat:     0.000001425

Those of us with Computer Science degrees are infamous for our nitpicking of details that do not affect the "bottom line". A classic example is arguing over which sorting algorithm to use. Sometimes we get so excited about the power we wield at our fingertips that we forget to get any work done.

So here's to us web developers caring less about saving 3.49e-7 seconds per concatenation and more about implementing functionality on time.

As Jeff Atwood points out, every algorithm is fast for small n.

(btw, I still will be using single-quote concatenation for its speed.)

Today's lyrics complements of blink-182's All the Small Things:

Late night, come home
Work sucks, I know
She left me roses by the stairs
Surprise let me know she cares

No comments: