Re: RFC: Add `final class Vector` to PHP

From: Date: Sat, 18 Sep 2021 00:00:45 +0000
Subject: Re: RFC: Add `final class Vector` to PHP
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-116080@lists.php.net to get a copy of this message
Hi Max Semenik, > Since Ds was mentioned, I've added it to your benchmark (code and complete results at > https://gist.github.com/MaxSem/d0ea0755d6deabaf88c9ef26039b2f27): > > Appending to array:         n= 1048576 iterations=      20 memory=33558608 bytes, > create+destroy time=0.369 read time = 0.210 result=10995105792000 > Appending to Vector:        n= 1048576 iterations=      20 memory=16777304 bytes, > create+destroy time=0.270 read time = 0.270 result=10995105792000 > Appending to SplStack:      n= 1048576 iterations=      20 memory=33554584 bytes, > create+destroy time=0.893 read time = 0.397 result=10995105792000 > Appending to SplFixedArray: n= 1048576 iterations=      20 memory=16777304 bytes, > create+destroy time=2.475 read time = 0.340 result=10995105792000 > Appending to Ds\Vector:     n= 1048576 iterations=      20 memory=24129632 bytes, > create+destroy time=0.389 read time = 0.305 result=10995105792000 > > Another comparison with Ds, I wonder if an interface akin to Ds\Sequence[1] could be added, to > have something in common with other future containers.. It's worth noting that the first 4 data structures all start with initial sizes that are powers of 2 and continue doubling (and not mattering for SplStack, a doubly linked list), but according to Ds\Vector's documentation, it starts with a minimum size of 10. So it's an unfair comparison. http://docs.php.net/manual/en/class.ds-vector.php#ds-vector.constants.min-capacity So there are probably larger copies done in Ds\Vector - Ds\Vector might do better for other sizes or use less memory under other circumstances. (for reasons mentioned in https://externals.io/message/116048#116054 , I haven't checked the resizing strategy used by Ds\Vector - doubling is a common choice in vector implementations in other languages, others use other multiples of old capacity, etc) Regards, - Tyson

« previous php.internals (#116080) next »