88
99class BenchTest extends \Codeception \Test \Unit
1010{
11+ private $ n = 10000 ;
12+
13+ public function testReadSliceView ()
14+ {
15+ $ n = $ this ->n ;
16+ $ originalArray = range (0 , $ n );
17+
18+ $ ts = \microtime (true );
19+ $ view = ArrayView::toView ($ originalArray );
20+ $ result = $ view ['::2 ' ];
21+ $ spent = \round (\microtime (true ) - $ ts , 4 );
22+
23+ echo "[testReadSliceView] SPENT: {$ spent } s \n" ;
24+ ob_flush ();
25+ }
26+
27+ public function testReadSlicePure ()
28+ {
29+ $ n = $ this ->n ;
30+ $ n_2 = intval ($ n / 2 );
31+ $ originalArray = range (0 , $ n );
32+
33+ $ ts = \microtime (true );
34+ $ result = [];
35+ for ($ i = 0 ; $ i < $ n_2 ; $ i ++) {
36+ $ result [$ i ] = $ originalArray [$ i * 2 ];
37+ }
38+ $ spent = \round (\microtime (true ) - $ ts , 4 );
39+
40+ echo "[testReadSlicePure] SPENT: {$ spent } s \n" ;
41+ ob_flush ();
42+ }
1143 public function testWriteSliceView ()
1244 {
13- $ n = 10000 ;
45+ $ n = $ this -> n ;
1446 $ n_2 = intval ($ n / 2 );
1547 $ originalArray = range (0 , $ n );
1648 $ toWrite = range (0 , $ n_2 );
@@ -20,13 +52,13 @@ public function testWriteSliceView()
2052 $ view ['::2 ' ] = $ toWrite ;
2153 $ spent = \round (\microtime (true ) - $ ts , 4 );
2254
23- echo "SPENT: {$ spent } s \n" ;
55+ echo "[testWriteSliceView] SPENT: {$ spent } s \n" ;
2456 ob_flush ();
2557 }
2658
2759 public function testWriteSlicePure ()
2860 {
29- $ n = 10000 ;
61+ $ n = $ this -> n ;
3062 $ n_2 = intval ($ n / 2 );
3163 $ originalArray = range (0 , $ n );
3264 $ toWrite = range (0 , $ n_2 );
@@ -37,7 +69,7 @@ public function testWriteSlicePure()
3769 }
3870 $ spent = \round (\microtime (true ) - $ ts , 4 );
3971
40- echo "SPENT: {$ spent } s \n" ;
72+ echo "[testWriteSlicePure] SPENT: {$ spent } s \n" ;
4173 ob_flush ();
4274 }
4375}
0 commit comments