Skip to content

Instantly share code, notes, and snippets.

@patrickallaert
Created August 26, 2015 00:15
Show Gist options
  • Save patrickallaert/9b5e19d9ed7d59c4fd52 to your computer and use it in GitHub Desktop.
Save patrickallaert/9b5e19d9ed7d59c4fd52 to your computer and use it in GitHub Desktop.
SplStack vs SplQueue
echo SplStack
echo ========
echo php 5.5
echo -------
for i in $(seq 10); do
time php5.5 -d memory_limit=-1 -n spl-stack.php
done
echo php 5.6
echo -------
for i in $(seq 10); do
time php5.6 -d memory_limit=-1 -n spl-stack.php
done
echo php 7.0
echo -------
for i in $(seq 10); do
time php7.0 -d memory_limit=-1 -n spl-stack.php
done
echo SplQueue
echo ========
echo php 5.5
echo -------
for i in $(seq 10); do
time php5.5 -d memory_limit=-1 -n spl-queue.php
done
echo php 5.6
echo -------
for i in $(seq 10); do
time php5.6 -d memory_limit=-1 -n spl-queue.php
done
echo php 7.0
echo -------
for i in $(seq 10); do
time php7.0 -d memory_limit=-1 -n spl-queue.php
done
SplStack
========
php 5.5
-------
int(964954848)
real 0m2.689s
user 0m2.498s
sys 0m0.191s
int(964954848)
real 0m2.692s
user 0m2.501s
sys 0m0.191s
int(964954848)
real 0m2.707s
user 0m2.512s
sys 0m0.195s
int(964954848)
real 0m2.680s
user 0m2.494s
sys 0m0.186s
int(964954848)
real 0m2.777s
user 0m2.606s
sys 0m0.171s
int(964954848)
real 0m2.717s
user 0m2.566s
sys 0m0.152s
int(964954848)
real 0m2.694s
user 0m2.534s
sys 0m0.160s
int(964954848)
real 0m2.703s
user 0m2.534s
sys 0m0.168s
int(964954848)
real 0m2.681s
user 0m2.507s
sys 0m0.174s
int(964954848)
real 0m2.753s
user 0m2.566s
sys 0m0.187s
php 5.6
-------
int(964954848)
real 0m2.689s
user 0m2.514s
sys 0m0.175s
int(964954848)
real 0m2.700s
user 0m2.533s
sys 0m0.167s
int(964954848)
real 0m2.713s
user 0m2.526s
sys 0m0.187s
int(964954848)
real 0m2.689s
user 0m2.510s
sys 0m0.179s
int(964954848)
real 0m2.700s
user 0m2.526s
sys 0m0.175s
int(964954848)
real 0m2.708s
user 0m2.550s
sys 0m0.158s
int(964954848)
real 0m2.698s
user 0m2.514s
sys 0m0.184s
int(964954848)
real 0m2.684s
user 0m2.535s
sys 0m0.149s
int(964954848)
real 0m2.716s
user 0m2.537s
sys 0m0.179s
int(964954848)
real 0m2.850s
user 0m2.680s
sys 0m0.170s
php 7.0
-------
int(402651320)
real 0m1.970s
user 0m1.947s
sys 0m0.023s
int(402651320)
real 0m1.971s
user 0m1.953s
sys 0m0.018s
int(402651320)
real 0m1.969s
user 0m1.950s
sys 0m0.019s
int(402651320)
real 0m1.976s
user 0m1.949s
sys 0m0.027s
int(402651320)
real 0m1.973s
user 0m1.954s
sys 0m0.019s
int(402651320)
real 0m1.977s
user 0m1.963s
sys 0m0.014s
int(402651320)
real 0m1.975s
user 0m1.952s
sys 0m0.023s
int(402651320)
real 0m1.979s
user 0m1.954s
sys 0m0.024s
int(402651320)
real 0m1.972s
user 0m1.943s
sys 0m0.029s
int(402651320)
real 0m1.983s
user 0m1.964s
sys 0m0.018s
SplQueue
========
php 5.5
-------
int(964954848)
real 0m2.680s
user 0m2.496s
sys 0m0.184s
int(964954848)
real 0m2.702s
user 0m2.519s
sys 0m0.183s
int(964954848)
real 0m2.682s
user 0m2.522s
sys 0m0.160s
int(964954848)
real 0m2.691s
user 0m2.507s
sys 0m0.184s
int(964954848)
real 0m2.732s
user 0m2.554s
sys 0m0.178s
int(964954848)
real 0m2.683s
user 0m2.528s
sys 0m0.155s
int(964954848)
real 0m2.846s
user 0m2.678s
sys 0m0.168s
int(964954848)
real 0m2.711s
user 0m2.546s
sys 0m0.165s
int(964954848)
real 0m2.697s
user 0m2.549s
sys 0m0.148s
int(964954848)
real 0m2.706s
user 0m2.524s
sys 0m0.182s
php 5.6
-------
int(964954848)
real 0m2.705s
user 0m2.521s
sys 0m0.184s
int(964954848)
real 0m2.711s
user 0m2.546s
sys 0m0.165s
int(964954848)
real 0m2.708s
user 0m2.543s
sys 0m0.165s
int(964954848)
real 0m2.759s
user 0m2.596s
sys 0m0.163s
int(964954848)
real 0m2.685s
user 0m2.493s
sys 0m0.192s
int(964954848)
real 0m2.699s
user 0m2.531s
sys 0m0.170s
int(964954848)
real 0m2.682s
user 0m2.498s
sys 0m0.184s
int(964954848)
real 0m2.719s
user 0m2.538s
sys 0m0.181s
int(964954848)
real 0m2.702s
user 0m2.517s
sys 0m0.185s
int(964954848)
real 0m2.712s
user 0m2.550s
sys 0m0.162s
php 7.0
-------
int(402651320)
real 0m2.280s
user 0m2.263s
sys 0m0.017s
int(402651320)
real 0m2.937s
user 0m2.919s
sys 0m0.018s
int(402651320)
real 0m1.977s
user 0m1.957s
sys 0m0.019s
int(402651320)
real 0m1.971s
user 0m1.949s
sys 0m0.022s
int(402651320)
real 0m1.974s
user 0m1.955s
sys 0m0.019s
int(402651320)
real 0m1.977s
user 0m1.955s
sys 0m0.023s
int(402651320)
real 0m1.970s
user 0m1.948s
sys 0m0.022s
int(402651320)
real 0m1.977s
user 0m1.952s
sys 0m0.025s
int(402651320)
real 0m1.971s
user 0m1.947s
sys 0m0.023s
int(402651320)
real 0m1.970s
user 0m1.946s
sys 0m0.024s
<?php
$start = memory_get_usage();
$all = [];
for ($j = 0; $j < 1e4; ++$j) {
$all[$j] = new SplQueue();
for ($i = 0; $i < 1e3; ++$i) {
$all[$j][] = $i;
}
}
var_dump(memory_get_usage() - $start);
<?php
$start = memory_get_usage();
$all = [];
for ($j = 0; $j < 1e4; ++$j) {
$all[$j] = new SplStack();
for ($i = 0; $i < 1e3; ++$i) {
$all[$j][] = $i;
}
}
var_dump(memory_get_usage() - $start);
SplStack SplQueue
php 5.5 php 5.6 php 7.0 php 5.5 php 5.6 php 7.0
Runs
#1 2,498 2,514 1,947 2,496 2,521 2,263
#2 2,501 2,533 1,953 2,519 2,546 2,919
#3 2,512 2,526 1,95 2,522 2,543 1,957
#4 2,494 2,51 1,949 2,507 2,596 1,949
#5 2,606 2,526 1,954 2,554 2,493 1,955
#6 2,566 2,55 1,963 2,528 2,531 1,955
#7 2,534 2,514 1,952 2,678 2,498 1,948
#8 2,534 2,535 1,954 2,546 2,538 1,952
#9 2,507 2,537 1,943 2,549 2,517 1,947
#10 2,566 2,68 1,964 2,524 2,55 1,946
Average : 2,5318 2,5425 1,9529 2,5423 2,5333 2,0791
Median : 2,523 2,5295 1,9525 2,526 2,5345 1,9535
Standard deviation : 0,0370908794 0,0498492171 0,0065396228 0,0510926174 0,029401625 0,31098319
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment