+ All Categories
Home > Software > Does the SPL still have any relevance in the Brave New World of PHP7?

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

Date post: 23-Jan-2018
Category:
Upload: mark-baker
View: 376 times
Download: 1 times
Share this document with a friend
43
Does the SPL still have any relevance in the Brave New World of PHP7?
Transcript

Does the SPL still have any relevance

in the Brave New World of PHP7?

Standard PHP Library

Since PHP 5.3.0

Provides• DataTypes• Autoloader• Interfaces• Iterators• Exceptions• DataStructures• File Handling• Miscellaneous Functions

DataTypes

DataTypesSPL Types

Experimental

Alternative to scalar type hinting

Not included in PHP build by default

TypesInt

Float

String

Bool

Enum

Autoloader

AutoloaderComposer

Phar

Interfaces

InterfacesIterator Interfaces

Countable

OuterIterator

RecursiveIterator

SeekableIterator

Pattern InterfacesSplObserver

SplSubject

Iterators

IteratorsArray/Collection Iterators

File/Folder Iterators

XML Iterators

Filter Iterators

Multiple Iterator

IteratorsGenerators

IteratorsIterators Generators

IteratorsIterators

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

IteratorsIterators 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

Exceptions

ExceptionsBadFunctionCallExceptionBadMethodCallExceptionDomainExceptionInvalidArgumentExceptionLengthExceptionLogicExceptionOutOfBoundsExceptionOutOfRangeExceptionOverflowExceptionRangeExceptionRuntimeExceptionUnderflowExceptionUnexpectedValueException

Exceptions\Exception

\LogicException

\BadFunctionCallException

\BadMethodCallException

\DomainException

\InvalidArgumentException

\LengthException

\OutOfRangeException

\RuntimeException

\OutOfBoundsException

\OverflowException

\RangeException

\UnderflowException

\UnexpectedValueException

Data Structures

Data StructuresFixed Array

Doubly-Linked List

Stack

Queue

Heap

Object Storage

Priority Queue

Data StructuresFixed Array

0.0

00

0

0.0

02

0

0.0

00

0

0.0

01

8

0.1

80

1

0.1

11

0

0.0

50

6

0.0

58

7

0.0

27

1

0.0

42

5

0.0

07

1

0.0

18

1

0.0

31

1

0.0

46

0

0.0

10

4

0.0

23

7

0.0

77

1

0.0

75

5

0.0

38

8

0.0

49

6

0.1

91

0

0.2

16

7

0.0

65

0

0.0

89

8

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

ArrayImplementation

SPLFixedArray ArrayImplementation

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)

Data StructuresDoubly-Linked List

0.1

68

6

0.3

15

4

0.0

44

3

0.1

57

8

0.0

25

1

0.0

32

3

0.0

05

9

0.0

16

7

0.0

32

5

0.0

42

9

0.0

10

1

0.0

21

9

0.2

01

7

0.1

02

9

0.0

62

1

0.0

29

5

141009.55

93754.86

32772.4539062.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

ArrayImplementation

SplDoublyLinkedList ArrayImplementation

SplDoublyLinkedList

PHP 5.6 PHP 7.1

Doubly-Linked List Performance

Push Sequential Sequential with Key Pop Memory (kb)

Data StructuresStack

7.2

99

2

4.8

51

5

2.1

87

5

2.1

34

2

9.5

12

9

5.0

89

9

2.6

31

4

1.5

00

8

285.05

190.65

68.5378.72

0

50

100

150

200

250

300

0

1

2

3

4

5

6

7

8

9

10

ArrayImplementation

SPLStack ArrayImplementation

SPLStack

PHP 5.6 PHP 7.1

Stack Performance

Time (s) Push Time (s) Pop Memory (kb)

Data StructuresQueue

6.8

31

4.9

95

1

2.3

79

5

2.0

71

3

13

6.4

63

5.1

46

7 54

.88

73

1.4

96

5

529.83

428.15409.97 418.91

0

100

200

300

400

500

600

0

20

40

60

80

100

120

140

160

ArrayImplementation

SPLQueue ArrayImplementation

SPLQueue

PHP 5.6 PHP 7.1

Queue Performance

Time (s) Enqueue Time (s) Dequeue Memory (kb)

Data StructuresHeap

0.1

06

3

0.1

77

1

0.0

83

3

0.1

13

1

0.2

11

7

0.1

54

8

0.0

93

7

0.0

66

2

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

ArrayImplementation

SPLHeap ArrayImplementation

SPLHeap

PHP 5.6 PHP 7.1

Heap Performance

Time (s) Build Time (s) Loop Memory (kb)

Data StructuresRudi Theunissen’s new PHP7 Datastructures

PECL

Githubhttps://github.com/php-ds

Bloghttps://medium.com/@rtheunissen/efficient-data-structures-for-php-7-9dda7af674cd

Rudi’s Data Structures• Stack

• Queue

• Priority Queue

• Sequence (List)

• Vector

• Deque (Double-Ended Queue)

• Map

• Set

Data StructuresStack

7.2

99

2

4.8

51

5

2.1

87

5

2.1

34

2

2.0

60

4

9.5

12

9

5.0

89

9

2.6

31

4

1.5

00

8

1.5

50

3

285.05

190.65

68.5378.72

44.49

0

50

100

150

200

250

300

0

1

2

3

4

5

6

7

8

9

10

ArrayImplementation

SPLStack ArrayImplementation

SPLStack Rudi's DS

PHP 5.6 PHP 7.1

Stack Performance

Time (s) Push Time (s) Pop Memory (kb)

Data StructuresQueue

6.8

31

4.9

95

1

2.3

79

5

2.0

71

3

2.1

44

4

13

6.4

63

5.1

46

7

54

.88

73

1.4

96

5

1.4

39

1

529.83

428.15409.97 418.91

372.7

0

100

200

300

400

500

600

0

20

40

60

80

100

120

140

160

ArrayImplementation

SPLQueue ArrayImplementation

SPLQueue Rudi's DS

PHP 5.6 PHP 7.1

Queue Performance

Time (s) Enqueue Time (s) Dequeue Memory (kb)

Files

FilesSplFileInfo

SplFileObject

SplTempFileObject

Assorted Functions

Assorted FunctionsClass 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

Assorted FunctionsReflection

Assorted FunctionsIterator 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

Standard PHP LibraryProvides

• DataTypes

• Autoloader

• Interfaces ?

• Iterators ?

• Exceptions

• DataStructures ?

• File Handling

• Miscellaneous Functions ?


Recommended