Skip to content

Instantly share code, notes, and snippets.

@gom
Created February 28, 2010 01:35
Show Gist options
  • Save gom/317110 to your computer and use it in GitHub Desktop.
Save gom/317110 to your computer and use it in GitHub Desktop.
<?php
require 'Benchmark/Timer.php';
$timer = new Benchmark_Timer();
$a = array(1,2,3,4,5);
$max = 20;
function _map($i) { return $i . 'hoge';}
$timer->start();
for ($i = 0; $i < $max; $i++) {
$c = array();
foreach($a as $b) {
$c[] = $b . 'hoge';
}
}
$timer->setMarker('foreach');
for ($i = 0; $i < $max; $i++) {
$c = array_map('_map', $a);
}
$timer->setMarker('array_map');
$timer->stop();
$timer->display();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment