PHP Array Performance

February 26th, 2010

Index Checking

The functional difference between array_key_exists($key, $array) and isset($array[$key]) is that isset returns false when the key exists but contains null. Functionality aside, there is a demonstrable performance difference.

$dataSet = array();
$size = 0x1FFFF;

$i = $size;
while ($i--)
	$dataSet[$i] = $i+1;

$start = microtime(true);

$i = $size;
while ($i--)
	array_key_exists($i, $dataSet); //isset($dataSet[$i]);

echo "Time: ". (microtime(true) - $start);

Sure enough, after averaging a few benchmarks together the outcome was clear.

isset
0.0248870849609
array_key_exists
0.604112148285

When performance is important target isset() when applicable. It’s even possible to use a fall through to increase performance, here’s an example from my Options class: if (!isset($this->_options[$resolvedName]) && !array_key_exists($resolvedName, $this->_options))

Append Performance

In the following test case there was no performance difference between usage of append or directly addressing an index.

$dataSet = array();
$size = 0x1FFFF;
$i = $size;

$start = microtime(true);

while ($i--)
	$dataSet[] = $i+1; //$dataSet[$i] = $i+1;

echo "Time: ". (microtime(true) - $start);

Remodeling PHP’s compact()/extract() into an OO Pattern

October 11th, 2009

A common usage, at least for extract(), has been to allow an associative array to be passed to a function for use as named optional parameters, however, there is a lot wrong with dumping an array into the symbol table and then checking if what you want exists or not.

I have designed a pattern that allows an object to accept and address public level optional named arguments without the problems that could be associated with the compact()/extract() pattern. This pattern does require at least PHP 5.3 (uses late static binding) and overloads __get/__set preventing the child class from doing so.

Read the rest of this entry »

Queryable Food Nutrition Database

October 7th, 2009

The USDA releases data for food nutritional information. I’ve taken this data and loaded it into my local database, and created a front end to allow it to be queryable.

Database Schema

database schema

Read the rest of this entry »

Message Hasher

October 5th, 2009

A small web-based message hasher, good for generating hashes of small amounts of text. No binary support yet, but it’s planned via file uploads!

Read the rest of this entry »

GraphicsPath Front – Vector drawing software

August 18th, 2009

screenshot

GraphicsPath Front is vector drawing software based upon the GraphicsPath .net class.

Download (source and binaries) — Execute \bin\debug\GraphicsPathFront.exe or compile from source.

Some of the notable features include:

There are several limitations in this program due to the limits of the underlying GraphicsPath class. Though the code is in place to do so, nodes can not be directly edited once created, for example. Nor can different paths be drawn using different pens.

Read the rest of this entry »

Boggle.exe

August 18th, 2009

screenshot

Boggle.exe is a computerized version of the Hasbro dice game. It’s intended to be played by multiple people infront of the computer using pens and paper, no internet play is supported as it’s ridiculously easy to cheat. The main neat feature of Boggle.exe over it’s physical counterpart is a board solver. Once the game is over, all of the valid words inside of the board are shown and can be highlighted (see picture).

Download (source and executable) — Extract to it’s own directory and run \bin\debug\Boggle.exe. words.txt must be in the same directory as the executable.

Installing Windows 7 from and to the same hard drive

August 17th, 2009

The reason why is pretty simple, DVDs are not remotely as fast as any other media, and in 2009, it’s starting to show. Flash drives are larger, faster, and more versatile than DVDs, and they’re costing less and less. But what about an older system that can not boot from USB storage? Well, there is an option, and that’s to use the destination drive as the source. Install the drive into a separate computer (via a usb dongle is fine) and follow these steps. Note that these directions work if you’re trying to make a bootable USB flash drive, too.

Read the rest of this entry »

Replacing an Inspiron 1525 LCD video

August 16th, 2009

Simple step by step guide to replacing the LCD on a Dell Inspiron 1525 laptop.

Read the rest of this entry »

Hacking Windows XP PowerToy Calculator to run in Vista

July 22nd, 2009

This was more of a project than I was originally expecting, Microsoft prevents the Windows XP Powertoy Calculator from running in Vista in 2 separate places, but in the end, it runs perfectly in Vista, all the limitations are false. (Edit: I can confirm that this hacked copy works in Windows 7, too!)

Don’t feel like doing this yourself? No need! :)

Read the rest of this entry »

Using Process Monitor and other tools to fix a broken installation.

July 22nd, 2009

Today the stars were aligned and my VMWare installation decided to stop working. It’s time for an upgrade, anyways.


Oh, that makes sense. So lets uninstall the old version.


Can’t install the new, can’t uninstall the old. Time for some hackery!

Read the rest of this entry »