Let’s look at a common php ‘optimization’ tip (note that I am only running this test on my computer, and I am not shutting things down to help it go faster).
Use single quotes ( ‘ ) instead of double quotes ( ” ) .
The reasoning behind this is that php parses double quoted strings for variables, so it takes way longer to process your evil double quoted strings than it does to parse your single quoted strings.
$test = 'something'; $repeats = 1000000; $start1 = microtime(true); $first = ''; for($i = 0; $i < $repeats; $i ++){ $first .= 'string '. $test; } $end1 = microtime(true); $time1 = ($end1 - $start1); $start2 = microtime(true); $second = ""; for($i = 0; $i < $repeats; $i ++){ $second .= "string $test"; } $end2 = microtime(true); $time2 = ($end2 - $start2); echo 'A difference of: '.($time2 - $time1) . ' seconds'; #=> A difference of approx: 0.244801044464 seconds;
A whopping 0.24 seconds over 1000000 string concatenations (a difference of about 0.00000024 per concatenation). I wouldn’t bother with this one, if the code is full of double quotes leave it.
Now, I am not suggesting that you rethink the micro optimizations that you make go ahead, make them if you must. But before you put too much thought into it, make those macro-optimizations that you are avoiding and clean up your code. Future you will thank you, especially if current you avoids dumb “micro-optimizations” like bit shifting rather than multiplying and dividing (dumb because for the most part, modern compilers make this optimization already, or your processor does a table lookup rather than doing the actual calculation).
#this: 9 * 256; #is way more readable than: 9 << 8;
No tags
17
Classic Game Walkthroughs Part 1: Space Invaders
2 Comments · Posted by SeanJA in Uncategorized
Welcome to the first installation of Classic Game Walkthroughs. Today we tackle the arcade classic Space Invaders.
Avoid the shots from the invaders. Shoot back. Repeat Until they are no more. Repeat until you run out of quarters.
[Update: zoe just informed me that they move! I added that information]
When c like languages say so
$a = 5; $b = 1; $result = $a---$b; echo $a; #=>4 echo $b; #=>1 echo $result; #=>4
public class FunMaths{ public static void main(String[] args) { int result; int a = 5, b = 1; result = a---b; System.out.println(a); System.out.println(b); System.out.println(result); } }
No tags

If this were Catbert: I could be... for the right price.
9
A couple useful jQuery Snippets
7 Comments · Posted by SeanJA in Javascript, Open Source, Programming, jQuery
For popups, just add class=”popup”
jQuery('a.popup').live('click', function(){ newwindow=window.open($(this).attr('href'),'','height=200,width=150'); if (window.focus) {newwindow.focus()} return false; });
To open in a new tab, add class=”newTab”
jQuery('a.newTab').live('click', function(){ newwindow=window.open($(this).href); jQuery(this).target = "_blank"; return false; });
Check if something is in view
function in_view(elem){ var docViewTop = jQuery(window).scrollTop(); var docViewBottom = docViewTop + jQuery(window).height(); var elemTop = jQuery(elem).offset().top; var elemBottom = elemTop + jQuery(elem).height(); return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom) && (elemBottom <= docViewBottom) && (elemTop >= docViewTop)); }
No tags

