SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
New SPL Features in PHP 5.3

                     Matthew Turland
         CodeWorks '09 Webcast Series
                        June 26, 2009
Salut! Comment sa-va?

●
    Senior Consultant at Blue Parabola
●   Native of Duson, Louisiana
●   Author and TE for php|architect Magazine
●   Book coming soon from php|architect
●   Contributor to Zend Framework project
A Long, Long Time Ago (Or Not)

              ●   Alexander Stepanov
              ●   Conceived of the
                  STL for C++
              ●
                  Goals of SPL are
                  somewhat similar
In a Galaxy Not So Far Away

Pre-5.3 SPL Features
●   Classes: ArrayObject, SplFileInfo...
●   Interfaces: ArrayAccess, Countable...
●   Exceptions: BadFunctionCallException...
●   Functions: spl_autoload_register...
Oh yeah, and iterators.
So What's New?

In comparison to the STL:
●   Iterators? Nope.
●   Algorithms? Nope.
●   Functors? Nope.
●   Well, there's only one thing left then...
Containers

“A container is a class, a data structure,
or an abstract data type whose instances
are collections of other objects. They are
used to store objects in an organized way
following specific access rules.”

“Container (data structure)” - Wikipedia
We Don't Need
 No Stinkin' Containers!

array()         'string'
Sure We Do! Here's Why...




      Scalability!!!
Arrays Are Great


●   They're a general purpose container.
●   This makes them flexible.
●   Its underlying algorithm isn't always best.
Benchmarks


●   Lies, Damned Lies, and Benchmarks - YMMV
●   PHP 5.3.0RC4 compiled on Ubuntu 9.04
●   Intel Core2Duo 1.83GHz, 4 GB DDR2-RAM
Benchmark Runner

#!/bin/bash
# 20 = # executions to perform
# 100 = # elements in the container
# ./bench.sh test.php 20 100
time=`/home/matt/Documents/Projects/php-
5.3.0RC4/build/php_build/bin/php-cgi -q -T $2 $1 $3
2>&1 | tail -n 1 | cut -d " " -f 3`;
avg=`echo "scale=6; $time / $2" | bc`;
echo "$1 $avg";
The List
SplFixedArray


●   Like an array, but with a fixed length.
●   Only allows integers >= 0 for keys.
●   Can be resized, but at a cost.
●   Great for simple enumerated lists.
SplFixedArray Code
<?php
$a = array();
for ($i = 0; $i < $argv[1]; $i++) {
    $a[$i] = $i;
}


<?php
$a = new SplFixedArray($argv[1]);
for ($i = 0; $i < $argv[1]; $i++) {
    $a[$i] = $i;
}
SplFixedArray Results
Elements        SplFixedArray   Array       Ratio

           10          371 µs      293 µs       1.266

       100             501 µs      783 µs       0.640

     1,000             899 µs    1,151 µs       0.781

    10,000           8,229 µs    9,628 µs       0.855

   100,000          49,481 µs   81,028 µs       0.610
SplFixedArray Graph
            90000
            80000
            70000
            60000
Time (µs)




            50000
            40000                                    SplFixedArray
            30000                                    Array
            20000
            10000
                0
                 10     100      1000 10000 100000
                              Elements
The Stack
SplStack


●   Last In, First Out (LIFO)
●   2 Operations
    ●   Push - [] for both
    ●   Pop – array_pop() vs ->pop()
SplStack Code

<?php
$a = array();
for($i = 0; $i < $argv[1]; $i++) {
    $a[] = $i;
}
for($i = 0; $i < $argv[1]; $i++) {
    array_pop($a);
}
SplStack Code (cont.)


<?php
$a = new SplStack;
for($i = 0; $i < $argv[1]; $i++) {
    $a[] = $i;
}
for($i = 0; $i < $argv[1]; $i++) {
    $a->pop();
}
SplStack Results
Elements         SplStack      Array        Ratio

           10         394 µs       311 µs       1.267

       100            595 µs       462 µs       1.288

     1,000          2,417 µs     2,021 µs       1.196

    10,000         15,525 µs    14,296 µs       1.086

   100,000       135,854 µs    124,955 µs       1.087
SplStack Graph
            160000
            140000
            120000
            100000
Time (μs)




             80000
                                                      SplStack
             60000
                                                      Array
             40000
             20000
                0
                 10   100       1000   10000 100000
                            Elements
The Queue
SplQueue


●   First In, First Out (FIFO)
●   2 Operations
    ●   Enqueue - [] for both
    ●   Dequeue – array_shift() vs ->dequeue()
SplQueue Code

<?php
$a = array();
for($i = 0; $i < $argv[1]; $i++) {
    $a[] = $i;
}
for($i = 0; $i < $argv[1]; $i++) {
    array_shift($a);
}
SplQueue Code (cont.)

<?php
$a = new SplQueue;
for($i = 0; $i < $argv[1]; $i++) {
    $a[] = $i;
}
for($i = 0; $i < $argv[1]; $i++) {
    $a->dequeue();
}
SplQueue Results
Elements         SplQueue         Array        Ratio

           10         390 µs         347 µs        1.124

       100            657 µs          811 µs       0.810

     1,000          2,918 µs       14,722 µs       0.198

    10,000         17,322 µs    1,440,558 µs       0.012

   100,000        137,136 µs   31,413,805 µs       0.004
SplQueue Graph
            35000000
            30000000
            25000000
Time (μs)




            20000000
            15000000
                                           SplQueue
            10000000                       Array
             5000000
                  0
                       100    10000
                   10     1000    100000
                      Elements
The Heap
SplHeap, SplMinHeap, SplMaxHeap


●   Highest / Lowest First Out
●   2 Operations
    ●   Insert - [] and sort() vs ->insert()
    ●   Remove – array_shift() vs ->extract()
SplMinHeap Code

<?php
$a = array();
for($i = 0; $i < $argv[1]; $i++) {
    $a[] = rand(1, $argv[1]);
    sort($a);
}
for($i = 0; $i < $argv[1]; $i++) {
    array_shift($a);
}
SplMinHeap Code (cont.)

<?php
$a = new SplMinHeap;
for($i = 0; $i < $argv[1]; $i++) {
    $a->insert(rand(1, $argv[1]));
}
for($i = 0; $i < $argv[1]; $i++) {
    $a->extract();
}
SplMinHeap Results
Elements        SplMinHeap        Array        Ratio

           10         516 µs         365 µs        1.414

       100            847 µs        2,698 µs       0.314

     1,000          4,629 µs     150,179 µs        0.031

    10,000         26,459 µs   23,144,131 µs       0.001

   100,000        371,613 µs   31,974,805 µs       0.012
SplMinHeap Graph
            35000000
            30000000
            25000000
Time (μs)




            20000000                             SplMinHeap
            15000000                             Array
            10000000
            5000000
                  0
                        100        10000
                   10         1000      100000
                        Elements
The Priority Queue
SplPriorityQueue


●   Operates similarly to a heap
●   In fact, uses a heap internally for storage
●   Accepts a priority with the element value
●   Element with highest priority comes out first
SplPriorityQueue Code
<?php
function priority_sort($a,$b) {
    return $a[1]-$b[1];
}
$a = array();
$threshold = (int) $argv[1] * 0.1;
for($i = 0; $i < $argv[1]; $i++) {
    $a[] = array($i, rand(1,10));
    usort($a, 'priority_sort');
    if ($i > $threshold) {
        array_shift($a);
    }
}
SplPriorityQueue Code (cont.)

  <?php
  $threshold = $argv[1] * 0.1;
  $a = new SplPriorityQueue;
  for($i = 0; $i < $argv[1]; $i++) {
      $a->insert($i, rand(1,10));
      if ($i > $threshold) {
          $a->extract();
      }
  }
SplPriorityQueue Results
Elements         SplPriorityQueue     Array         Ratio

            10             369 µs         450 µs            0.820

           100             818 µs        4,583 µs           0.178

      1,000              6,752 µs     346,094 µs            0.020

     10,000            39,308 µs    30,710,530 µs           0.001

    100,000           484,752 µs    30,587,806 µs           0.016
SplPriorityQueue Graph
            35000000
            30000000
            25000000
Time (μs)




            20000000
                                                            SplPriorityQueue
            15000000
                                                            Array
            10000000
            5000000
                  0
                   10     100       1000   10000   100000
                                Elements
By the way, thank this guy




     Etienne Kneuss
Some Great SPL Resources


●
    http://php.net/spl
●   http://colder.ch
●
    http://blueparabola.com/blog/spl-deserves-some-reiteration
●
    http://elizabethmariesmith.com/slides/spl_to_the_rescue.pdf
C'est tous!
●
    http://ishouldbecoding.com
●   http://www.blueparabola.com/blogs/matthew-turland
●   matt@ishouldbecoding.com or matthew@blueparabola.com
●   Elazar on the Freenode IRC network
●   Look for me in Dallas, Atlanta, Miami,
    Washington, and New York City
    at CodeWorks 2009!
●   Watch for my book next quarter!
                                             Source: Christian Flickinger

Weitere ähnliche Inhalte

Was ist angesagt?

Jscex: Write Sexy JavaScript
Jscex: Write Sexy JavaScriptJscex: Write Sexy JavaScript
Jscex: Write Sexy JavaScriptjeffz
 
In a galaxy far, far away - A procedural generation tale
In a galaxy far, far away - A procedural generation taleIn a galaxy far, far away - A procedural generation tale
In a galaxy far, far away - A procedural generation taleShay Davidson
 
Spider Performance Test(Bench Mark04242009)
Spider Performance Test(Bench Mark04242009)Spider Performance Test(Bench Mark04242009)
Spider Performance Test(Bench Mark04242009)Kentoku
 
San diego hug lens presentation
San diego hug lens presentationSan diego hug lens presentation
San diego hug lens presentationSiva Jayaraman
 
Useful functions for arrays in php
Useful functions for arrays in phpUseful functions for arrays in php
Useful functions for arrays in phpChetan Patel
 
D9 Process Book_Expedition Mars
D9 Process Book_Expedition MarsD9 Process Book_Expedition Mars
D9 Process Book_Expedition MarsMatthew Fisher
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Developmentvito jeng
 
λ | Lenses
λ | Lensesλ | Lenses
λ | LensesOpen-IT
 
Functional Patterns for the non-mathematician
Functional Patterns for the non-mathematicianFunctional Patterns for the non-mathematician
Functional Patterns for the non-mathematicianBrian Lonsdorf
 
Pure function And Functional Error Handling
Pure function And Functional Error HandlingPure function And Functional Error Handling
Pure function And Functional Error HandlingGyooha Kim
 
FunScript 2013 (with speakers notes)
FunScript 2013 (with speakers notes)FunScript 2013 (with speakers notes)
FunScript 2013 (with speakers notes)Zach Bray
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kirill Rozov
 
Extend R with Rcpp!!!
Extend R with Rcpp!!!Extend R with Rcpp!!!
Extend R with Rcpp!!!mickey24
 
Drools5 Community Training Module 3 Drools Expert DRL Syntax
Drools5 Community Training Module 3 Drools Expert DRL SyntaxDrools5 Community Training Module 3 Drools Expert DRL Syntax
Drools5 Community Training Module 3 Drools Expert DRL SyntaxMauricio (Salaboy) Salatino
 

Was ist angesagt? (20)

SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Jscex: Write Sexy JavaScript
Jscex: Write Sexy JavaScriptJscex: Write Sexy JavaScript
Jscex: Write Sexy JavaScript
 
SVGo workshop
SVGo workshopSVGo workshop
SVGo workshop
 
In a galaxy far, far away - A procedural generation tale
In a galaxy far, far away - A procedural generation taleIn a galaxy far, far away - A procedural generation tale
In a galaxy far, far away - A procedural generation tale
 
Spider Performance Test(Bench Mark04242009)
Spider Performance Test(Bench Mark04242009)Spider Performance Test(Bench Mark04242009)
Spider Performance Test(Bench Mark04242009)
 
San diego hug lens presentation
San diego hug lens presentationSan diego hug lens presentation
San diego hug lens presentation
 
Useful functions for arrays in php
Useful functions for arrays in phpUseful functions for arrays in php
Useful functions for arrays in php
 
D9 Process Book_Expedition Mars
D9 Process Book_Expedition MarsD9 Process Book_Expedition Mars
D9 Process Book_Expedition Mars
 
JavaScript Web Development
JavaScript Web DevelopmentJavaScript Web Development
JavaScript Web Development
 
λ | Lenses
λ | Lensesλ | Lenses
λ | Lenses
 
Functional Patterns for the non-mathematician
Functional Patterns for the non-mathematicianFunctional Patterns for the non-mathematician
Functional Patterns for the non-mathematician
 
Millionways
MillionwaysMillionways
Millionways
 
Beyond Scala Lens
Beyond Scala LensBeyond Scala Lens
Beyond Scala Lens
 
Pure function And Functional Error Handling
Pure function And Functional Error HandlingPure function And Functional Error Handling
Pure function And Functional Error Handling
 
1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basics
 
FunScript 2013 (with speakers notes)
FunScript 2013 (with speakers notes)FunScript 2013 (with speakers notes)
FunScript 2013 (with speakers notes)
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 
Extend R with Rcpp!!!
Extend R with Rcpp!!!Extend R with Rcpp!!!
Extend R with Rcpp!!!
 
ScalaMeter 2014
ScalaMeter 2014ScalaMeter 2014
ScalaMeter 2014
 
Drools5 Community Training Module 3 Drools Expert DRL Syntax
Drools5 Community Training Module 3 Drools Expert DRL SyntaxDrools5 Community Training Module 3 Drools Expert DRL Syntax
Drools5 Community Training Module 3 Drools Expert DRL Syntax
 

Andere mochten auch

New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3Matthew Turland
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPatrick Allaert
 

Andere mochten auch (6)

Sinatra
SinatraSinatra
Sinatra
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3
 
SPL Datastructures
SPL DatastructuresSPL Datastructures
SPL Datastructures
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
 

Ähnlich wie New SPL Features in PHP 5.3 (TEK-X)

Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance PuzzlersDoug Hawkins
 
Gotcha! Ruby things that will come back to bite you.
Gotcha! Ruby things that will come back to bite you.Gotcha! Ruby things that will come back to bite you.
Gotcha! Ruby things that will come back to bite you.David Tollmyr
 
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Dhivyaa C.R
 
Understanding the Disruptor
Understanding the DisruptorUnderstanding the Disruptor
Understanding the DisruptorTrisha Gee
 
ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine Aleksandar Prokopec
 
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...JAX London
 
Getting Functional with Scala
Getting Functional with ScalaGetting Functional with Scala
Getting Functional with ScalaJorge Paez
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyKimikazu Kato
 
01_introduction_lab.pdf
01_introduction_lab.pdf01_introduction_lab.pdf
01_introduction_lab.pdfzehiwot hone
 
Swift Ready for Production?
Swift Ready for Production?Swift Ready for Production?
Swift Ready for Production?Crispy Mountain
 
Locks? We Don't Need No Stinkin' Locks - Michael Barker
Locks? We Don't Need No Stinkin' Locks - Michael BarkerLocks? We Don't Need No Stinkin' Locks - Michael Barker
Locks? We Don't Need No Stinkin' Locks - Michael BarkerJAX London
 
Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Michael Barker
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithmspppepito86
 
Consider the following C code snippet C codevoid setArray(int.pdf
Consider the following C code snippet C codevoid setArray(int.pdfConsider the following C code snippet C codevoid setArray(int.pdf
Consider the following C code snippet C codevoid setArray(int.pdfarihantmum
 
Ns2: Introduction - Part I
Ns2: Introduction - Part INs2: Introduction - Part I
Ns2: Introduction - Part IAjit Nayak
 
Joker 2015 - Валеев Тагир - Что же мы измеряем?
Joker 2015 - Валеев Тагир - Что же мы измеряем?Joker 2015 - Валеев Тагир - Что же мы измеряем?
Joker 2015 - Валеев Тагир - Что же мы измеряем?tvaleev
 

Ähnlich wie New SPL Features in PHP 5.3 (TEK-X) (20)

Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance Puzzlers
 
Gotcha! Ruby things that will come back to bite you.
Gotcha! Ruby things that will come back to bite you.Gotcha! Ruby things that will come back to bite you.
Gotcha! Ruby things that will come back to bite you.
 
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
 
UNIT IV (4).pptx
UNIT IV (4).pptxUNIT IV (4).pptx
UNIT IV (4).pptx
 
Understanding the Disruptor
Understanding the DisruptorUnderstanding the Disruptor
Understanding the Disruptor
 
ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine
 
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
 
Getting Functional with Scala
Getting Functional with ScalaGetting Functional with Scala
Getting Functional with Scala
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPy
 
01_introduction_lab.pdf
01_introduction_lab.pdf01_introduction_lab.pdf
01_introduction_lab.pdf
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
Swift Ready for Production?
Swift Ready for Production?Swift Ready for Production?
Swift Ready for Production?
 
Locks? We Don't Need No Stinkin' Locks - Michael Barker
Locks? We Don't Need No Stinkin' Locks - Michael BarkerLocks? We Don't Need No Stinkin' Locks - Michael Barker
Locks? We Don't Need No Stinkin' Locks - Michael Barker
 
Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
Consider the following C code snippet C codevoid setArray(int.pdf
Consider the following C code snippet C codevoid setArray(int.pdfConsider the following C code snippet C codevoid setArray(int.pdf
Consider the following C code snippet C codevoid setArray(int.pdf
 
Ns2: Introduction - Part I
Ns2: Introduction - Part INs2: Introduction - Part I
Ns2: Introduction - Part I
 
TreSQL
TreSQL TreSQL
TreSQL
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Joker 2015 - Валеев Тагир - Что же мы измеряем?
Joker 2015 - Валеев Тагир - Что же мы измеряем?Joker 2015 - Валеев Тагир - Что же мы измеряем?
Joker 2015 - Валеев Тагир - Что же мы измеряем?
 

Mehr von Matthew Turland

Open Source Networking with Vyatta
Open Source Networking with VyattaOpen Source Networking with Vyatta
Open Source Networking with VyattaMatthew Turland
 
When RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTPWhen RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTPMatthew Turland
 
Open Source Content Management Systems
Open Source Content Management SystemsOpen Source Content Management Systems
Open Source Content Management SystemsMatthew Turland
 
PHP Basics for Designers
PHP Basics for DesignersPHP Basics for Designers
PHP Basics for DesignersMatthew Turland
 
Creating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandCreating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandMatthew Turland
 
The OpenSolaris Operating System and Sun xVM VirtualBox - Blake Deville
The OpenSolaris Operating System and Sun xVM VirtualBox - Blake DevilleThe OpenSolaris Operating System and Sun xVM VirtualBox - Blake Deville
The OpenSolaris Operating System and Sun xVM VirtualBox - Blake DevilleMatthew Turland
 
Utilizing the Xen Hypervisor in business practice - Bryan Fusilier
Utilizing the Xen Hypervisor in business practice - Bryan FusilierUtilizing the Xen Hypervisor in business practice - Bryan Fusilier
Utilizing the Xen Hypervisor in business practice - Bryan FusilierMatthew Turland
 
The Ruby Programming Language - Ryan Farnell
The Ruby Programming Language - Ryan FarnellThe Ruby Programming Language - Ryan Farnell
The Ruby Programming Language - Ryan FarnellMatthew Turland
 
PDQ Programming Languages plus an overview of Alice - Frank Ducrest
PDQ Programming Languages plus an overview of Alice - Frank DucrestPDQ Programming Languages plus an overview of Alice - Frank Ducrest
PDQ Programming Languages plus an overview of Alice - Frank DucrestMatthew Turland
 
Getting Involved in Open Source - Matthew Turland
Getting Involved in Open Source - Matthew TurlandGetting Involved in Open Source - Matthew Turland
Getting Involved in Open Source - Matthew TurlandMatthew Turland
 

Mehr von Matthew Turland (11)

Open Source Networking with Vyatta
Open Source Networking with VyattaOpen Source Networking with Vyatta
Open Source Networking with Vyatta
 
When RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTPWhen RSS Fails: Web Scraping with HTTP
When RSS Fails: Web Scraping with HTTP
 
Open Source Content Management Systems
Open Source Content Management SystemsOpen Source Content Management Systems
Open Source Content Management Systems
 
PHP Basics for Designers
PHP Basics for DesignersPHP Basics for Designers
PHP Basics for Designers
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
Creating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandCreating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew Turland
 
The OpenSolaris Operating System and Sun xVM VirtualBox - Blake Deville
The OpenSolaris Operating System and Sun xVM VirtualBox - Blake DevilleThe OpenSolaris Operating System and Sun xVM VirtualBox - Blake Deville
The OpenSolaris Operating System and Sun xVM VirtualBox - Blake Deville
 
Utilizing the Xen Hypervisor in business practice - Bryan Fusilier
Utilizing the Xen Hypervisor in business practice - Bryan FusilierUtilizing the Xen Hypervisor in business practice - Bryan Fusilier
Utilizing the Xen Hypervisor in business practice - Bryan Fusilier
 
The Ruby Programming Language - Ryan Farnell
The Ruby Programming Language - Ryan FarnellThe Ruby Programming Language - Ryan Farnell
The Ruby Programming Language - Ryan Farnell
 
PDQ Programming Languages plus an overview of Alice - Frank Ducrest
PDQ Programming Languages plus an overview of Alice - Frank DucrestPDQ Programming Languages plus an overview of Alice - Frank Ducrest
PDQ Programming Languages plus an overview of Alice - Frank Ducrest
 
Getting Involved in Open Source - Matthew Turland
Getting Involved in Open Source - Matthew TurlandGetting Involved in Open Source - Matthew Turland
Getting Involved in Open Source - Matthew Turland
 

Kürzlich hochgeladen

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 

Kürzlich hochgeladen (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 

New SPL Features in PHP 5.3 (TEK-X)

  • 1. New SPL Features in PHP 5.3 Matthew Turland CodeWorks '09 Webcast Series June 26, 2009
  • 2. Salut! Comment sa-va? ● Senior Consultant at Blue Parabola ● Native of Duson, Louisiana ● Author and TE for php|architect Magazine ● Book coming soon from php|architect ● Contributor to Zend Framework project
  • 3. A Long, Long Time Ago (Or Not) ● Alexander Stepanov ● Conceived of the STL for C++ ● Goals of SPL are somewhat similar
  • 4. In a Galaxy Not So Far Away Pre-5.3 SPL Features ● Classes: ArrayObject, SplFileInfo... ● Interfaces: ArrayAccess, Countable... ● Exceptions: BadFunctionCallException... ● Functions: spl_autoload_register...
  • 5. Oh yeah, and iterators.
  • 6. So What's New? In comparison to the STL: ● Iterators? Nope. ● Algorithms? Nope. ● Functors? Nope. ● Well, there's only one thing left then...
  • 7. Containers “A container is a class, a data structure, or an abstract data type whose instances are collections of other objects. They are used to store objects in an organized way following specific access rules.” “Container (data structure)” - Wikipedia
  • 8. We Don't Need No Stinkin' Containers! array() 'string'
  • 9. Sure We Do! Here's Why... Scalability!!!
  • 10. Arrays Are Great ● They're a general purpose container. ● This makes them flexible. ● Its underlying algorithm isn't always best.
  • 11. Benchmarks ● Lies, Damned Lies, and Benchmarks - YMMV ● PHP 5.3.0RC4 compiled on Ubuntu 9.04 ● Intel Core2Duo 1.83GHz, 4 GB DDR2-RAM
  • 12. Benchmark Runner #!/bin/bash # 20 = # executions to perform # 100 = # elements in the container # ./bench.sh test.php 20 100 time=`/home/matt/Documents/Projects/php- 5.3.0RC4/build/php_build/bin/php-cgi -q -T $2 $1 $3 2>&1 | tail -n 1 | cut -d " " -f 3`; avg=`echo "scale=6; $time / $2" | bc`; echo "$1 $avg";
  • 14. SplFixedArray ● Like an array, but with a fixed length. ● Only allows integers >= 0 for keys. ● Can be resized, but at a cost. ● Great for simple enumerated lists.
  • 15. SplFixedArray Code <?php $a = array(); for ($i = 0; $i < $argv[1]; $i++) { $a[$i] = $i; } <?php $a = new SplFixedArray($argv[1]); for ($i = 0; $i < $argv[1]; $i++) { $a[$i] = $i; }
  • 16. SplFixedArray Results Elements SplFixedArray Array Ratio 10 371 µs 293 µs 1.266 100 501 µs 783 µs 0.640 1,000 899 µs 1,151 µs 0.781 10,000 8,229 µs 9,628 µs 0.855 100,000 49,481 µs 81,028 µs 0.610
  • 17. SplFixedArray Graph 90000 80000 70000 60000 Time (µs) 50000 40000 SplFixedArray 30000 Array 20000 10000 0 10 100 1000 10000 100000 Elements
  • 19. SplStack ● Last In, First Out (LIFO) ● 2 Operations ● Push - [] for both ● Pop – array_pop() vs ->pop()
  • 20. SplStack Code <?php $a = array(); for($i = 0; $i < $argv[1]; $i++) { $a[] = $i; } for($i = 0; $i < $argv[1]; $i++) { array_pop($a); }
  • 21. SplStack Code (cont.) <?php $a = new SplStack; for($i = 0; $i < $argv[1]; $i++) { $a[] = $i; } for($i = 0; $i < $argv[1]; $i++) { $a->pop(); }
  • 22. SplStack Results Elements SplStack Array Ratio 10 394 µs 311 µs 1.267 100 595 µs 462 µs 1.288 1,000 2,417 µs 2,021 µs 1.196 10,000 15,525 µs 14,296 µs 1.086 100,000 135,854 µs 124,955 µs 1.087
  • 23. SplStack Graph 160000 140000 120000 100000 Time (μs) 80000 SplStack 60000 Array 40000 20000 0 10 100 1000 10000 100000 Elements
  • 25. SplQueue ● First In, First Out (FIFO) ● 2 Operations ● Enqueue - [] for both ● Dequeue – array_shift() vs ->dequeue()
  • 26. SplQueue Code <?php $a = array(); for($i = 0; $i < $argv[1]; $i++) { $a[] = $i; } for($i = 0; $i < $argv[1]; $i++) { array_shift($a); }
  • 27. SplQueue Code (cont.) <?php $a = new SplQueue; for($i = 0; $i < $argv[1]; $i++) { $a[] = $i; } for($i = 0; $i < $argv[1]; $i++) { $a->dequeue(); }
  • 28. SplQueue Results Elements SplQueue Array Ratio 10 390 µs 347 µs 1.124 100 657 µs 811 µs 0.810 1,000 2,918 µs 14,722 µs 0.198 10,000 17,322 µs 1,440,558 µs 0.012 100,000 137,136 µs 31,413,805 µs 0.004
  • 29. SplQueue Graph 35000000 30000000 25000000 Time (μs) 20000000 15000000 SplQueue 10000000 Array 5000000 0 100 10000 10 1000 100000 Elements
  • 31. SplHeap, SplMinHeap, SplMaxHeap ● Highest / Lowest First Out ● 2 Operations ● Insert - [] and sort() vs ->insert() ● Remove – array_shift() vs ->extract()
  • 32. SplMinHeap Code <?php $a = array(); for($i = 0; $i < $argv[1]; $i++) { $a[] = rand(1, $argv[1]); sort($a); } for($i = 0; $i < $argv[1]; $i++) { array_shift($a); }
  • 33. SplMinHeap Code (cont.) <?php $a = new SplMinHeap; for($i = 0; $i < $argv[1]; $i++) { $a->insert(rand(1, $argv[1])); } for($i = 0; $i < $argv[1]; $i++) { $a->extract(); }
  • 34. SplMinHeap Results Elements SplMinHeap Array Ratio 10 516 µs 365 µs 1.414 100 847 µs 2,698 µs 0.314 1,000 4,629 µs 150,179 µs 0.031 10,000 26,459 µs 23,144,131 µs 0.001 100,000 371,613 µs 31,974,805 µs 0.012
  • 35. SplMinHeap Graph 35000000 30000000 25000000 Time (μs) 20000000 SplMinHeap 15000000 Array 10000000 5000000 0 100 10000 10 1000 100000 Elements
  • 37. SplPriorityQueue ● Operates similarly to a heap ● In fact, uses a heap internally for storage ● Accepts a priority with the element value ● Element with highest priority comes out first
  • 38. SplPriorityQueue Code <?php function priority_sort($a,$b) { return $a[1]-$b[1]; } $a = array(); $threshold = (int) $argv[1] * 0.1; for($i = 0; $i < $argv[1]; $i++) { $a[] = array($i, rand(1,10)); usort($a, 'priority_sort'); if ($i > $threshold) { array_shift($a); } }
  • 39. SplPriorityQueue Code (cont.) <?php $threshold = $argv[1] * 0.1; $a = new SplPriorityQueue; for($i = 0; $i < $argv[1]; $i++) { $a->insert($i, rand(1,10)); if ($i > $threshold) { $a->extract(); } }
  • 40. SplPriorityQueue Results Elements SplPriorityQueue Array Ratio 10 369 µs 450 µs 0.820 100 818 µs 4,583 µs 0.178 1,000 6,752 µs 346,094 µs 0.020 10,000 39,308 µs 30,710,530 µs 0.001 100,000 484,752 µs 30,587,806 µs 0.016
  • 41. SplPriorityQueue Graph 35000000 30000000 25000000 Time (μs) 20000000 SplPriorityQueue 15000000 Array 10000000 5000000 0 10 100 1000 10000 100000 Elements
  • 42. By the way, thank this guy Etienne Kneuss
  • 43. Some Great SPL Resources ● http://php.net/spl ● http://colder.ch ● http://blueparabola.com/blog/spl-deserves-some-reiteration ● http://elizabethmariesmith.com/slides/spl_to_the_rescue.pdf
  • 44. C'est tous! ● http://ishouldbecoding.com ● http://www.blueparabola.com/blogs/matthew-turland ● matt@ishouldbecoding.com or matthew@blueparabola.com ● Elazar on the Freenode IRC network ● Look for me in Dallas, Atlanta, Miami, Washington, and New York City at CodeWorks 2009! ● Watch for my book next quarter! Source: Christian Flickinger