1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
<?php
function one($y) {
echo 'Length: ' . strlen($y) . PHP_EOL;
} # one()
function two(&$y) {
echo 'Length: ' . strlen($y) . PHP_EOL;
} # two()
class Dto {
var $title;
var $author;
var $date;
var $messageid;
var $idlist;
function Dto($title, $author, $date, $messageid, $idlist) {
$this->title = $title;
$this->author = $author;
$this->date = $date;
$this->messageid = $messageid;
$this->idlist = $idlist;
} # ctor
} # class Spotinfo
$objList = array();
$arList = array();
$y = microtime(true);
for($i = 0; $i < 10000; $i++) {
$x = new Dto('title', 'author', '01 april 2012', '<asdlksjjkslda98213890jsdalkda@bliep.net>', array('<asdlksjjkslda98213890jsdalkda@bliep.net>'));
$objList[] = $x;
} # for
echo 'Object run time: ' . (microtime(true) - $y) . PHP_EOL;
$y = microtime(true);
for($i = 0; $i < 10000; $i++) {
$x = array('title' => 'title',
'author' => 'author',
'date' => '01 april 2012',
'messageid' => '<asdlksjjkslda98213890jsdalkda@bliep.net>',
'idlist' => array('<sdkdsalksdaljkd@bliep.net>'));
$arList[] = $x;
} # for
echo 'Array run time: ' . (microtime(true) - $y) . PHP_EOL;
$x = str_repeat('aaaaa', 12 * 1024);
$y = array($x, $x, $x);
$y = microtime(true);
one($x);
echo 'Passing not per reference: ' . ((microtime(true) - $y) * 1000) . PHP_EOL;
$y = microtime(true);
two($x);
echo 'Passing per reference: ' . ((microtime(true) - $y) * 1000) . PHP_EOL;
|