File tree Expand file tree Collapse file tree 2 files changed +45
-3
lines changed
Expand file tree Collapse file tree 2 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -406,11 +406,10 @@ public function set($newValues): self
406406 throw new SizeError ("Length of values array not equal to view length ( {$ dataSize } != {$ thisSize }). " );
407407 }
408408
409- $ newValuesView = ArrayView::toView ($ newValues );
410-
411409 $ size = \count ($ this );
410+
412411 for ($ i = 0 ; $ i < $ size ; $ i ++) {
413- $ this [$ i ] = $ newValuesView [$ i ];
412+ $ this [$ i ] = $ newValues [$ i ];
414413 }
415414
416415 return $ this ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Smoren \ArrayView \Tests \Unit \Examples ;
6+
7+ use Smoren \ArrayView \Views \ArrayView ;
8+
9+ class BenchTest extends \Codeception \Test \Unit
10+ {
11+ public function testWriteSliceView ()
12+ {
13+ $ n = 10000 ;
14+ $ n_2 = intval ($ n / 2 );
15+ $ originalArray = range (0 , $ n );
16+ $ toWrite = range (0 , $ n_2 );
17+
18+ $ ts = \microtime (true );
19+ $ view = ArrayView::toView ($ originalArray );
20+ $ view ['::2 ' ] = $ toWrite ;
21+ $ spent = \round (\microtime (true ) - $ ts , 4 );
22+
23+ echo "SPENT: {$ spent } s \n" ;
24+ ob_flush ();
25+ }
26+
27+ public function testWriteSlicePure ()
28+ {
29+ $ n = 10000 ;
30+ $ n_2 = intval ($ n / 2 );
31+ $ originalArray = range (0 , $ n );
32+ $ toWrite = range (0 , $ n_2 );
33+
34+ $ ts = \microtime (true );
35+ for ($ i = 0 ; $ i < $ n_2 ; $ i ++) {
36+ $ originalArray [$ i * 2 ] = $ toWrite [$ i ];
37+ }
38+ $ spent = \round (\microtime (true ) - $ ts , 4 );
39+
40+ echo "SPENT: {$ spent } s \n" ;
41+ ob_flush ();
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments