PHP
array_filter($data, function($row) { return substr($row, 0, 1) === "a"; });
Ibyegeranyo
$data->filter(function($row) { return substr($row, 0, 1) === "a"; });
PHP
array_search(function($row) { return substr($row, 0, 1) === "a"; }, $data);
Ibyegeranyo
$data->search(function($row) { return substr($row, 0, 1) === "a"; });
PHP
array_map(function($row) { return "test"; }, $data);
Ibyegeranyo
$data->map(function($row) { return "test"; });
PHP
sort($data);
Ibyegeranyo
$data->sort();
PHP
foreach($loop as $item) { $doSomething = true; }
Ibyegeranyo
$data->each(function($row) { return "test"; });
PHP
array_reduce($data, function($carry, $row) { return $carry + strlen($row); });
Ibyegeranyo
$data->reduce(function($carry, $row) { return $carry + strlen($row); });
PHP
array_splice($data, count($data)/2);
Ibyegeranyo
$data->splice(count($data)/2);
Byose hamwe (PHP)
$data = array_filter($data, function($row) { return substr($row, 0, 1) === "a"; }); $data = array_search(function($row) { return substr($row, 0, 1) === "a"; }, $data); $data = array_map(function($row) { return "test"; }, $data); sort($data); foreach($loop as $item) { $doSomething = true; } $sum = array_reduce($data, function($carry, $row) { return $carry + strlen($row); });
Byose hamwe (Ibyegeranyo)
$sum = $data->filter(function($row) { return substr($row, 0, 1) === "a"; })->search(function($row) { return substr($row, 0, 1) === "a"; })->map(function($row) { return "test"; })->sort() ->each(function($row) { return "test"; })->reduce(function($carry, $row) { return $carry + strlen($row); });
Kugereranya
Hamwe nuburyo bworoshye, ntabwo bisa nkaho habaho gucuruza cyane mubisomwa kuri buri gikorwa cyumuntu ku giti cye, nubwo iyo urebye urugero aho ukeneye byose kugirango bikoreshwe kumurongo umwe, urashobora kubona neza ko ari byinshi mu magambo ahinnye kandi yoroshye gusoma mugihe ukoresheje iminyururu-uburyo mu cyegeranyo.
Buri array yari ifite imirongo 100.000 idasanzwe nkibintu, kandi nayoboye buri gikorwa inshuro 100. Mugusoza, twabaze impuzandengo y'ibihe byose byo gusubiza.
========== Tests Complete (ms) ========== php filter: 5.07 collect filter: 6.49 ======================= php search: 0.79 collect search: 0 ======================= php map: 3.45 collect map: 4.18 ======================= php sort: 25.27 collect sort: 11.18 ======================= php each: 1.03 collect each: 6.96 ======================= php reduce: 2.78 collect reduce: 7.75 ======================= php splice: 1 collect splice: 0.74 =======================
Akayunguruzo , Ikarita , Foreach , na Kugabanya byose byihuse hamwe nibikorwa bisanzwe bya PHP. Foreach na Kugabanya mubyukuri itandukaniro ridasanzwe. Shakisha , Gutondeka , na Splice byose byerekana Ibyegeranyo nkuwatsinze, kandi Sort mubyukuri ni igihe kinini.
Mubitekerezo byanjye (kandi ni igitekerezo gishingiye gusa kubisubizo), niba imikorere ari impungenge nini, nakomezanya nibikorwa bisanzwe bya PHP kumasoko ya Foreach byanze bikunze kandi birashoboka ko ari kimwe kugabanya ibyo ukeneye byose. Niba ukeneye gukora uburyo ubwo aribwo bwose kuri datasets nini, biragaragara ko Ibyegeranyo aribwo buryo bwiza bwo kugenda. Ibisigaye biregeranye cyane kuburyo byunvikana nkibyifuzo byawe bwite.
Biragaragara, ugomba gufata aya makuru hanyuma ugafata icyemezo cyawe bwite, icyakora, niba umeze nkanjye, ndatekereza ko uzisanga unyerera mu byegeranyo byinshi muribi bikorwa hejuru. Ariko ndatekereza ko nzahamagara inyuma nkoresha →each
na →reduce
aho bikwiye kujya imbere!