Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Does the SPL still have any relevance in the Brave New World of PHP7?

271 views

Published on

Slides from the presentation given at PHPBenelux in January 2018

Published in: Software
  • Be the first to comment

  • Be the first to like this

Does the SPL still have any relevance in the Brave New World of PHP7?

  1. 1. Does the SPL still have any relevance in the Brave New World of PHP7?
  2. 2. Standard PHP Library Since PHP 5.3.0 Provides • DataTypes • Autoloader • Interfaces • Iterators • Exceptions • DataStructures • File Handling • Miscellaneous Functions
  3. 3. DataTypes
  4. 4. DataTypes SPL Types Experimental Alternative to scalar type hinting Not included in PHP build by default Types Int Float String Bool Enum
  5. 5. Autoloader
  6. 6. Autoloader Composer Phar
  7. 7. Interfaces
  8. 8. Interfaces Iterator Interfaces Countable OuterIterator RecursiveIterator SeekableIterator Pattern Interfaces SplObserver SplSubject
  9. 9. Iterators
  10. 10. Iterators Array/Collection Iterators File/Folder Iterators XML Iterators Filter Iterators Multiple Iterator
  11. 11. Iterators Generators
  12. 12. Iterators Iterators Generators
  13. 13. Iterators Iterators Call Time: 0.1447 Memory: 361.05 k Peak Memory: 397.48 k Generators Call Time: 0.0900 Memory: 357.20 k Peak Memory: 395.33 k
  14. 14. Iterators Iterators Generators • Less Userland Code • Core Iterators are already Tested • Potentially Slower • Potentially less memory efficient • More Userland Code • Requires Userland Testing • No Rewind • Can’t be Extended
  15. 15. Exceptions
  16. 16. Exceptions BadFunctionCallException BadMethodCallException DomainException InvalidArgumentException LengthException LogicException OutOfBoundsException OutOfRangeException OverflowException RangeException RuntimeException UnderflowException UnexpectedValueException
  17. 17. Exceptions Exception LogicException BadFunctionCallException BadMethodCallException DomainException InvalidArgumentException LengthException OutOfRangeException RuntimeException OutOfBoundsException OverflowException RangeException UnderflowException UnexpectedValueException
  18. 18. Data Structures
  19. 19. Data Structures Fixed Array Doubly-Linked List Stack Queue Heap Object Storage Priority Queue
  20. 20. Data Structures Fixed Array 0.0000 0.0020 0.0000 0.0018 0.1801 0.1110 0.0506 0.0587 0.0271 0.0425 0.0071 0.0181 0.0311 0.0460 0.0104 0.0237 0.0771 0.0755 0.0388 0.0496 0.1910 0.2167 0.0650 0.0898 141010.14 54692.95 32772.13 15628.48 0 20000 40000 60000 80000 100000 120000 140000 160000 0.0000 0.0500 0.1000 0.1500 0.2000 0.2500 Array Implementation SPLFixedArray Array Implementation SPLFixedArray PHP 5.6 PHP 7.1 Fixed Array Performance Time (s) Initialise Time (s) Set Time (s) Sequential Time (s) Sequential with Key Time (s) Random Time (s) Pop Memory (kb)
  21. 21. Data Structures Doubly-Linked List 0.1686 0.3154 0.0443 0.1578 0.0251 0.0323 0.0059 0.0167 0.0325 0.0429 0.0101 0.0219 0.2017 0.1029 0.0621 0.0295 141009.55 93754.86 32772.45 39062.82 0 20000 40000 60000 80000 100000 120000 140000 160000 0.0000 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500 Array Implementation SplDoublyLinkedList Array Implementation SplDoublyLinkedList PHP 5.6 PHP 7.1 Doubly-Linked List Performance Push Sequential Sequential with Key Pop Memory (kb)
  22. 22. Data Structures Stack 7.2992 4.8515 2.1875 2.1342 9.5129 5.0899 2.6314 1.5008 285.05 190.65 68.53 78.72 0 50 100 150 200 250 300 0 1 2 3 4 5 6 7 8 9 10 Array Implementation SPLStack Array Implementation SPLStack PHP 5.6 PHP 7.1 Stack Performance Time (s) Push Time (s) Pop Memory (kb)
  23. 23. Data Structures Queue 6.831 4.9951 2.3795 2.0713 136.463 5.1467 54.8873 1.4965 529.83 428.15 409.97 418.91 0 100 200 300 400 500 600 0 20 40 60 80 100 120 140 160 Array Implementation SPLQueue Array Implementation SPLQueue PHP 5.6 PHP 7.1 Queue Performance Time (s) Enqueue Time (s) Dequeue Memory (kb)
  24. 24. Data Structures Heap 0.1063 0.1771 0.0833 0.1131 0.2117 0.1548 0.0937 0.0662 20118.98 15564.69 12017.67 9846.63 0 5000 10000 15000 20000 25000 0 0.05 0.1 0.15 0.2 0.25 Array Implementation SPLHeap Array Implementation SPLHeap PHP 5.6 PHP 7.1 Heap Performance Time (s) Build Time (s) Loop Memory (kb)
  25. 25. Data Structures Rudi Theunissen’s new PHP7 Datastructures PECL Extension Github https://github.com/php-ds PHP Documentation http://php.net/manual/en/book.ds.php Blog https://medium.com/@rtheunissen/efficient-data-structures-for-php-7-9dda7af674cd
  26. 26. Rudi’s Data Structures • Stack • Queue • Priority Queue • Sequence (List) • Vector • Deque (Double-Ended Queue) • Map • Set
  27. 27. Files
  28. 28. Files SplFileInfo SplFileObject SplTempFileObject
  29. 29. Assorted Functions
  30. 30. Assorted Functions Class Functions: class_implements() — Return the interfaces which are implemented by the given class or interface class_parents() — Return the parent classes of the given class class_uses() — Return the traits used by the given class
  31. 31. Assorted Functions Reflection
  32. 32. Assorted Functions Iterator Functions: iterator_apply() — Call a function for every element in an iterator iterator_count() — Count the elements in an iterator iterator_to_array() — Copy the iterator into an array
  33. 33. Standard PHP Library Provides • DataTypes  • Autoloader  • Interfaces ? • Iterators ? • Exceptions  • DataStructures ? • File Handling  • Miscellaneous Functions ?

×