-
Notifications
You must be signed in to change notification settings - Fork 3
/
benchmark_is_array_countable.php
46 lines (36 loc) · 1.27 KB
/
benchmark_is_array_countable.php
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
<?php
declare(strict_types=1);
/** @noinspection AutoloadingIssuesInspection */
$numbers = range(0, 1000);
include "Collection.php";
$instances=100000;
$exist=true;
$array1=['repeated'=>'abc','b'=>'bcd','c'=>'def',20,30,40];
$array2=['repeated'=>'abc','d'=>'abc2','e'=>'bcd2','f'=>'def2',50,60,70];
$noarray=20;
// **********************************************************************************
$t1=microtime(true);
for($i=0;$i<$instances;$i++) {
$r=is_countable($array1);
$r=is_countable($noarray);
}
$t2=microtime(true);
$table['is_countable']=$t2-$t1;
// **********************************************************************************
$t1=microtime(true);
for($i=0;$i<$instances;$i++) {
$r=is_array($array1)? count($array1) : null;
$r=is_array($noarray)? count($noarray) : null;
}
$t2=microtime(true);
$table['is_array count']=$t2-$t1;
// **********************************************************************************
$t1=microtime(true);
for($i=0;$i<$instances;$i++) {
is_array($array1) and $r=count($array1);
is_array($noarray) and $r=count($noarray);
}
$t2=microtime(true);
$table['is_array count 2']=$t2-$t1;
// **********************************************************************************
echo \mapache_commons\Collection::generateTable($table);