-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjco.php
78 lines (58 loc) · 1.62 KB
/
jco.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
ini_set("memory_limit", "512M");
$data = range(1, 500000);
$t1 = microtime(true);
$m1 = memory_get_usage();
$jar = new \JCO\DArray(500000, 0);
foreach($data as $index => &$val) {
$jar[$index] = $val * 3;
}
echo "JCO\Darray" . PHP_EOL;
echo "TIME: " . (microtime(true) - $t1) . PHP_EOL;
echo "MEMORY: " . ((memory_get_usage() - $m1)/1048576) . PHP_EOL;
gc_collect_cycles();
$t1 = microtime(true);
$m1 = memory_get_usage();
$nar = $jar->filter(function($n) {return $n % 2 == 0;});
echo "JCO\Darray filter" . PHP_EOL;
echo "TIME: " . (microtime(true) - $t1) . PHP_EOL;
echo "MEMORY: " . ((memory_get_usage() - $m1)/1048576) . PHP_EOL;
gc_collect_cycles();
$t1 = microtime(true);
$m1 = memory_get_usage();
$nar = new \JCO\DArray(250000, 10000);
$i = 0;
foreach($jar as $val) {
if($val % 2 == 0) {
$nar[$i] = $val;
$i++;
}
}
echo "JCO\Darray filter foreach" . PHP_EOL;
echo "TIME: " . (microtime(true) - $t1) . PHP_EOL;
echo "MEMORY: " . ((memory_get_usage() - $m1)/1048576) . PHP_EOL;
unset($jar);
unset($newArr);
gc_collect_cycles();
$t1 = microtime(true);
$m1 = memory_get_usage();
$ar = [];
foreach($data as $index => &$val) {
$ar[$index] = $val * 3;
}
echo "Array" . PHP_EOL;
echo "TIME: " . (microtime(true) - $t1) . PHP_EOL;
echo "MEMORY: " . ((memory_get_usage() - $m1)/1048576) . PHP_EOL;
gc_collect_cycles();
$t1 = microtime(true);
$m1 = memory_get_usage();
$newAr = [];
foreach($ar as $index => &$val) {
if($val % 2 == 0) {
$newAr[] = $val;
}
}
echo "Array filter" . PHP_EOL;
echo "TIME: " . (microtime(true) - $t1) . PHP_EOL;
echo "MEMORY: " . ((memory_get_usage() - $m1)/1048576) . PHP_EOL;
gc_collect_cycles();