## Test: set unique vs. !isset

This checks the cost of checking if you're already written a value when that's never true.

Run this test again Return to test menu## Result: Discarded

The test labeled "**!isset()**" was the faster by

*0.0506*seconds, (4.542% faster)

The **!isset()** test took **1.0626** seconds.

The **set** test took **1.1131** seconds.

## Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 280,414 loops for a total of 5,608,280 runs.

- Line execution difference (0.000009) milliseconds.

- Avg difference (2.528) milliseconds per 280,414 loops.

- Total difference 50.56 milliseconds for 5,608,280 loops

The iteration variablity for Code 1 was (5.5836) milliseconds and Code 2 was (4.4290) milliseconds. The lower and the closer together there values are the more accurate the results are.

## Code

The first test, "**set**", was:

$array = array(); for ($n = 0; $n < 100; $n++) { $k = $n; $array[$k] = $n + 42; }

The second test, "**!isset()**", was:

$array = array(); for ($n = 0; $n < 100; $n++) { $k = $n; if (!isset($array[$k])) $array[$k] = $n + 42; }