derickr/xdebug — pull request #15 by taavi (2012-02-09 19:34:00+00:00)
Title: Use a flat array for line coverage. (take 2)

I've rebased and done some extra cleanup (amazing what 6 months and fresh eyes will do). I also ran benchmarks again, this time with public code!

Using PHP 5.3.10 x86_64 compiled on OSX 10.6.8, run on a 3.2GHz i3 with 8GB 1333MHz RAM.

Each timing is the mean of 10 runs of PHPUnit 3.6 (sebastianbergmann/phpunit@5d0ff52bdff9afd479e38fdc880adce453ce88e5). Before each run of 10, I ran it 3 times in a row and threw out those results.

for x in {1..10}; do time ./phpunit.php 2>&1 >/dev/null; done

Before (derickr:master derickr/xdebug@004b99c8a8ad3b2a1986c931a1585e9d71a4b39a):
real avg 18.414 s
user avg 15.76 s
sys avg 2.3133 s

After (taavi:coverage_line_array2 taavi/xdebug@cae8255ea43b9bc2087256968d20e221fa0863fb):
real avg 17.666 s (4% improvement over before)
user avg 15.0101 s (5% improvement over before)
sys avg 2.2652 s (2% improvement over before)

I suspect it also reduces memory usage (given the cost of the hash tables and linked list entries vs 1-byte-per-line-in-a-file) and almost certainly reduces memory fragmentation (one alloc, and probably a few reallocs per file vs alloc-per-line).

Thanks!