note 39035 added to function.array-push

From: Date: Thu, 15 Jan 2004 05:30:31 +0000
Subject: note 39035 added to function.array-push
Groups: php.notes 
Request: Send a blank email to php-notes+get-63581@lists.php.net to get a copy of this message
Adding to confirm the post below(daijoubuNOSP at Mvideotron dot ca) I first tested this by looping through 50,000 times using only the [] method, then 50,000 using the array_push method. Both times started on empty arrays, since it was for loops, it only appended integers, nothing big. function FullMicroTime() { $mictime = explode(" ", microtime()); return Do8Digit((intval($mictime[1]) + floatval($mictime[0]))); } function Do8Digit($string) { return sprintf("%.8f", $string); } $test = $test2 = array(); $f_test_begin = FullMicroTime(); for($i = 0; $i <= 50000; $i++) { $test[] = $i; } $f_test_end = FullMicroTime(); $s_test_begin = FullMicroTime(); for($i = 0; $i <= 50000; $i++) { array_push($test2, $i); } $s_test_end = FullMicroTime(); $first_time = Do8Digit(($f_test_end - $f_test_begin)); $second_time = Do8Digit(($s_test_end - $s_test_begin)); print '[] method: ' . $first_time . "\n"; print 'push method: ' . $second_time . "\n"; print 'difference: ' . Do8Digit(($second_time - $first_time)) . "\n"; My results were: [] method: 0.37957907 push method: 0.46931005 difference: 0.08973098 It's not much, and i'm sure no one will loop 50,000 times, but it's proof. ---- Manual Page -- http://www.php.net/manual/en/function.array-push.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39035 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39035&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39035&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#63581) next »