Larger simulation of adding and removing items from queue in PHP
up vote
1
down vote
favorite
My friend got the next test assignment. Implement a class Item as part of a larger simulation of adding and removing items from queue.
The add method adds the number at the end of queue, get method removes first number from the queue and returns it.
class Item
{
public function __construct(){
}
public function add($number){
}
public function get(){
}
}
We tried everything that came to our mind, but the execution time does not fall below 15sec for 50.000 iterations. Does anyone know a better solution to this problem?
Test case:
$n = 50000;
for ($i=0; $i < $n ; $i++) {
$item->add("Test".$i);
}
for ($i=0; $i < $n ; $i++) {
echo $item->get()."n";
}
Here's what we've tried:
With array_shift:
$this->numbers = $number;
return array_shift($this->numbers);
times elapsed in secs:
22.661945819855 |
23.122117042542 |
21.985857009888 |
22.498090982437
array_shift and array_push:
array_push($this->numbers, $number);
return array_shift($this->numbers);
times elapsed in secs: 25.500070095062 |
22.558148860931 |
21.946757078171 |
22.031461000443
unset:
array_push($this->numbers, $number);
$key = key($this->numbers);
$n = $this->numbers[$key];
unset($this->numbers[$key]);
return $n;
times elapsed in secs: 18.401049852371 |
14.445369958878 |
15.184392929077 |
16.063473939896
array_splice:
array_push($this->numbers, $number);
$key = key($this->numbers);
$n = $this->numbers[$key];
array_splice($this->numbers, $key, 1);
return $n;
times elapsed in secs: 49.540771007538 |
47.315555810928 |
46.451086997986 |
46.475464820862
SplDoublyLinkedList:
$this->numbers = new SplDoublyLinkedList();
$this->numbers->push($passportNumber);
return $this->numbers->shift();
times elapsed in secs: 18.166617155075 |
17.268024921417 |
15.621854066849 |
18.711433887482
Linked lists:
class ListNode
{
public $data;
public $next;
function __construct($data)
{
$this->data = $data;
$this->next = NULL;
}
}
class Item
{
$this->firstNode = null;
$this->lastNode = null;
public function add($number)
{
$link = new ListNode($number);
if ($this->firstNode === null) {
$this->firstNode = &$link;
$this->lastNode = &$link;
} else {
$this->lastNode->next = &$link;
$this->lastNode = &$link;
}
}
public function get()
{
if ($this->firstNode === null) {
return null;
}
$n = $this->firstNode->data;
$this->firstNode = $this->firstNode->next;
return $n;
}
}
times elapsed in secs: 19.694635868073 |
17.934485912323 |
18.973595142365 |
18.013978004456
php arrays queue
add a comment |
up vote
1
down vote
favorite
My friend got the next test assignment. Implement a class Item as part of a larger simulation of adding and removing items from queue.
The add method adds the number at the end of queue, get method removes first number from the queue and returns it.
class Item
{
public function __construct(){
}
public function add($number){
}
public function get(){
}
}
We tried everything that came to our mind, but the execution time does not fall below 15sec for 50.000 iterations. Does anyone know a better solution to this problem?
Test case:
$n = 50000;
for ($i=0; $i < $n ; $i++) {
$item->add("Test".$i);
}
for ($i=0; $i < $n ; $i++) {
echo $item->get()."n";
}
Here's what we've tried:
With array_shift:
$this->numbers = $number;
return array_shift($this->numbers);
times elapsed in secs:
22.661945819855 |
23.122117042542 |
21.985857009888 |
22.498090982437
array_shift and array_push:
array_push($this->numbers, $number);
return array_shift($this->numbers);
times elapsed in secs: 25.500070095062 |
22.558148860931 |
21.946757078171 |
22.031461000443
unset:
array_push($this->numbers, $number);
$key = key($this->numbers);
$n = $this->numbers[$key];
unset($this->numbers[$key]);
return $n;
times elapsed in secs: 18.401049852371 |
14.445369958878 |
15.184392929077 |
16.063473939896
array_splice:
array_push($this->numbers, $number);
$key = key($this->numbers);
$n = $this->numbers[$key];
array_splice($this->numbers, $key, 1);
return $n;
times elapsed in secs: 49.540771007538 |
47.315555810928 |
46.451086997986 |
46.475464820862
SplDoublyLinkedList:
$this->numbers = new SplDoublyLinkedList();
$this->numbers->push($passportNumber);
return $this->numbers->shift();
times elapsed in secs: 18.166617155075 |
17.268024921417 |
15.621854066849 |
18.711433887482
Linked lists:
class ListNode
{
public $data;
public $next;
function __construct($data)
{
$this->data = $data;
$this->next = NULL;
}
}
class Item
{
$this->firstNode = null;
$this->lastNode = null;
public function add($number)
{
$link = new ListNode($number);
if ($this->firstNode === null) {
$this->firstNode = &$link;
$this->lastNode = &$link;
} else {
$this->lastNode->next = &$link;
$this->lastNode = &$link;
}
}
public function get()
{
if ($this->firstNode === null) {
return null;
}
$n = $this->firstNode->data;
$this->firstNode = $this->firstNode->next;
return $n;
}
}
times elapsed in secs: 19.694635868073 |
17.934485912323 |
18.973595142365 |
18.013978004456
php arrays queue
what php version are you using and what is your pc config:) 'cause with the array_shift implementation I've got this result for add and get - 0.044579982757568 3.9010820388794
– myxaxa
Nov 20 at 11:15
PHP 7.1.16 on Macbook Pro 2011, i5, 8GB RAM. We also get that result when nothing is printed. If method get returns the number that is removed from the list and echo/print then the time increases.
– MajklRS
Nov 20 at 11:20
yeah, of course the get method is the heaviest one - cause array_shift is fat method. u can improve it as to use array_slice on 1000 elements for example. I'll try to solve it now
– myxaxa
Nov 20 at 11:27
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
My friend got the next test assignment. Implement a class Item as part of a larger simulation of adding and removing items from queue.
The add method adds the number at the end of queue, get method removes first number from the queue and returns it.
class Item
{
public function __construct(){
}
public function add($number){
}
public function get(){
}
}
We tried everything that came to our mind, but the execution time does not fall below 15sec for 50.000 iterations. Does anyone know a better solution to this problem?
Test case:
$n = 50000;
for ($i=0; $i < $n ; $i++) {
$item->add("Test".$i);
}
for ($i=0; $i < $n ; $i++) {
echo $item->get()."n";
}
Here's what we've tried:
With array_shift:
$this->numbers = $number;
return array_shift($this->numbers);
times elapsed in secs:
22.661945819855 |
23.122117042542 |
21.985857009888 |
22.498090982437
array_shift and array_push:
array_push($this->numbers, $number);
return array_shift($this->numbers);
times elapsed in secs: 25.500070095062 |
22.558148860931 |
21.946757078171 |
22.031461000443
unset:
array_push($this->numbers, $number);
$key = key($this->numbers);
$n = $this->numbers[$key];
unset($this->numbers[$key]);
return $n;
times elapsed in secs: 18.401049852371 |
14.445369958878 |
15.184392929077 |
16.063473939896
array_splice:
array_push($this->numbers, $number);
$key = key($this->numbers);
$n = $this->numbers[$key];
array_splice($this->numbers, $key, 1);
return $n;
times elapsed in secs: 49.540771007538 |
47.315555810928 |
46.451086997986 |
46.475464820862
SplDoublyLinkedList:
$this->numbers = new SplDoublyLinkedList();
$this->numbers->push($passportNumber);
return $this->numbers->shift();
times elapsed in secs: 18.166617155075 |
17.268024921417 |
15.621854066849 |
18.711433887482
Linked lists:
class ListNode
{
public $data;
public $next;
function __construct($data)
{
$this->data = $data;
$this->next = NULL;
}
}
class Item
{
$this->firstNode = null;
$this->lastNode = null;
public function add($number)
{
$link = new ListNode($number);
if ($this->firstNode === null) {
$this->firstNode = &$link;
$this->lastNode = &$link;
} else {
$this->lastNode->next = &$link;
$this->lastNode = &$link;
}
}
public function get()
{
if ($this->firstNode === null) {
return null;
}
$n = $this->firstNode->data;
$this->firstNode = $this->firstNode->next;
return $n;
}
}
times elapsed in secs: 19.694635868073 |
17.934485912323 |
18.973595142365 |
18.013978004456
php arrays queue
My friend got the next test assignment. Implement a class Item as part of a larger simulation of adding and removing items from queue.
The add method adds the number at the end of queue, get method removes first number from the queue and returns it.
class Item
{
public function __construct(){
}
public function add($number){
}
public function get(){
}
}
We tried everything that came to our mind, but the execution time does not fall below 15sec for 50.000 iterations. Does anyone know a better solution to this problem?
Test case:
$n = 50000;
for ($i=0; $i < $n ; $i++) {
$item->add("Test".$i);
}
for ($i=0; $i < $n ; $i++) {
echo $item->get()."n";
}
Here's what we've tried:
With array_shift:
$this->numbers = $number;
return array_shift($this->numbers);
times elapsed in secs:
22.661945819855 |
23.122117042542 |
21.985857009888 |
22.498090982437
array_shift and array_push:
array_push($this->numbers, $number);
return array_shift($this->numbers);
times elapsed in secs: 25.500070095062 |
22.558148860931 |
21.946757078171 |
22.031461000443
unset:
array_push($this->numbers, $number);
$key = key($this->numbers);
$n = $this->numbers[$key];
unset($this->numbers[$key]);
return $n;
times elapsed in secs: 18.401049852371 |
14.445369958878 |
15.184392929077 |
16.063473939896
array_splice:
array_push($this->numbers, $number);
$key = key($this->numbers);
$n = $this->numbers[$key];
array_splice($this->numbers, $key, 1);
return $n;
times elapsed in secs: 49.540771007538 |
47.315555810928 |
46.451086997986 |
46.475464820862
SplDoublyLinkedList:
$this->numbers = new SplDoublyLinkedList();
$this->numbers->push($passportNumber);
return $this->numbers->shift();
times elapsed in secs: 18.166617155075 |
17.268024921417 |
15.621854066849 |
18.711433887482
Linked lists:
class ListNode
{
public $data;
public $next;
function __construct($data)
{
$this->data = $data;
$this->next = NULL;
}
}
class Item
{
$this->firstNode = null;
$this->lastNode = null;
public function add($number)
{
$link = new ListNode($number);
if ($this->firstNode === null) {
$this->firstNode = &$link;
$this->lastNode = &$link;
} else {
$this->lastNode->next = &$link;
$this->lastNode = &$link;
}
}
public function get()
{
if ($this->firstNode === null) {
return null;
}
$n = $this->firstNode->data;
$this->firstNode = $this->firstNode->next;
return $n;
}
}
times elapsed in secs: 19.694635868073 |
17.934485912323 |
18.973595142365 |
18.013978004456
php arrays queue
php arrays queue
asked Nov 20 at 10:58
MajklRS
313
313
what php version are you using and what is your pc config:) 'cause with the array_shift implementation I've got this result for add and get - 0.044579982757568 3.9010820388794
– myxaxa
Nov 20 at 11:15
PHP 7.1.16 on Macbook Pro 2011, i5, 8GB RAM. We also get that result when nothing is printed. If method get returns the number that is removed from the list and echo/print then the time increases.
– MajklRS
Nov 20 at 11:20
yeah, of course the get method is the heaviest one - cause array_shift is fat method. u can improve it as to use array_slice on 1000 elements for example. I'll try to solve it now
– myxaxa
Nov 20 at 11:27
add a comment |
what php version are you using and what is your pc config:) 'cause with the array_shift implementation I've got this result for add and get - 0.044579982757568 3.9010820388794
– myxaxa
Nov 20 at 11:15
PHP 7.1.16 on Macbook Pro 2011, i5, 8GB RAM. We also get that result when nothing is printed. If method get returns the number that is removed from the list and echo/print then the time increases.
– MajklRS
Nov 20 at 11:20
yeah, of course the get method is the heaviest one - cause array_shift is fat method. u can improve it as to use array_slice on 1000 elements for example. I'll try to solve it now
– myxaxa
Nov 20 at 11:27
what php version are you using and what is your pc config:) 'cause with the array_shift implementation I've got this result for add and get - 0.044579982757568 3.9010820388794
– myxaxa
Nov 20 at 11:15
what php version are you using and what is your pc config:) 'cause with the array_shift implementation I've got this result for add and get - 0.044579982757568 3.9010820388794
– myxaxa
Nov 20 at 11:15
PHP 7.1.16 on Macbook Pro 2011, i5, 8GB RAM. We also get that result when nothing is printed. If method get returns the number that is removed from the list and echo/print then the time increases.
– MajklRS
Nov 20 at 11:20
PHP 7.1.16 on Macbook Pro 2011, i5, 8GB RAM. We also get that result when nothing is printed. If method get returns the number that is removed from the list and echo/print then the time increases.
– MajklRS
Nov 20 at 11:20
yeah, of course the get method is the heaviest one - cause array_shift is fat method. u can improve it as to use array_slice on 1000 elements for example. I'll try to solve it now
– myxaxa
Nov 20 at 11:27
yeah, of course the get method is the heaviest one - cause array_shift is fat method. u can improve it as to use array_slice on 1000 elements for example. I'll try to solve it now
– myxaxa
Nov 20 at 11:27
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
the main part the time is taken on is the get method and it's array_shift. you can use array_slice instead on 1000 elements for example:
<?php
class Item
{
protected $numbers = ;
public function add($number){
$this->numbers[$number] = true;
}
public function get(){
$x = key($this->numbers);
unset($this->numbers[$x]);
return $x;
}
}
ob_start();
$n = 50000;
$item = new Item();
$start = microtime(true);
for ($i=0; $i < $n ; $i++) {
$item->add("Test".$i);
}
echo microtime(true)-$start;
echo "rn";
$start = microtime(true);
for ($i=0; $i < $n ; $i++) {
echo $item->get() . "rn";
}
echo microtime(true)-$start;
ob_end_flush();
Yes, that is correct 0.082641124725342, 0.18116903305054. But you forgot to print the numbers. When you change to echo $item->get()."n", execution time is 14.767911911011.
– MajklRS
Nov 20 at 11:43
A small note, every time the number is requested, it is necessary to remove it from the queue.
– MajklRS
Nov 20 at 11:49
are you running it via cli or via browser? I suppose that 14 extra seconds come from the tcp the data is transferred by when you use browser :)
– myxaxa
Nov 20 at 11:53
I am running it from cli.
– MajklRS
Nov 20 at 12:07
so, I've updated the post - can you test again pls? cause for me it was always fast:)
– myxaxa
Nov 20 at 13:25
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391510%2flarger-simulation-of-adding-and-removing-items-from-queue-in-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
the main part the time is taken on is the get method and it's array_shift. you can use array_slice instead on 1000 elements for example:
<?php
class Item
{
protected $numbers = ;
public function add($number){
$this->numbers[$number] = true;
}
public function get(){
$x = key($this->numbers);
unset($this->numbers[$x]);
return $x;
}
}
ob_start();
$n = 50000;
$item = new Item();
$start = microtime(true);
for ($i=0; $i < $n ; $i++) {
$item->add("Test".$i);
}
echo microtime(true)-$start;
echo "rn";
$start = microtime(true);
for ($i=0; $i < $n ; $i++) {
echo $item->get() . "rn";
}
echo microtime(true)-$start;
ob_end_flush();
Yes, that is correct 0.082641124725342, 0.18116903305054. But you forgot to print the numbers. When you change to echo $item->get()."n", execution time is 14.767911911011.
– MajklRS
Nov 20 at 11:43
A small note, every time the number is requested, it is necessary to remove it from the queue.
– MajklRS
Nov 20 at 11:49
are you running it via cli or via browser? I suppose that 14 extra seconds come from the tcp the data is transferred by when you use browser :)
– myxaxa
Nov 20 at 11:53
I am running it from cli.
– MajklRS
Nov 20 at 12:07
so, I've updated the post - can you test again pls? cause for me it was always fast:)
– myxaxa
Nov 20 at 13:25
|
show 3 more comments
up vote
0
down vote
the main part the time is taken on is the get method and it's array_shift. you can use array_slice instead on 1000 elements for example:
<?php
class Item
{
protected $numbers = ;
public function add($number){
$this->numbers[$number] = true;
}
public function get(){
$x = key($this->numbers);
unset($this->numbers[$x]);
return $x;
}
}
ob_start();
$n = 50000;
$item = new Item();
$start = microtime(true);
for ($i=0; $i < $n ; $i++) {
$item->add("Test".$i);
}
echo microtime(true)-$start;
echo "rn";
$start = microtime(true);
for ($i=0; $i < $n ; $i++) {
echo $item->get() . "rn";
}
echo microtime(true)-$start;
ob_end_flush();
Yes, that is correct 0.082641124725342, 0.18116903305054. But you forgot to print the numbers. When you change to echo $item->get()."n", execution time is 14.767911911011.
– MajklRS
Nov 20 at 11:43
A small note, every time the number is requested, it is necessary to remove it from the queue.
– MajklRS
Nov 20 at 11:49
are you running it via cli or via browser? I suppose that 14 extra seconds come from the tcp the data is transferred by when you use browser :)
– myxaxa
Nov 20 at 11:53
I am running it from cli.
– MajklRS
Nov 20 at 12:07
so, I've updated the post - can you test again pls? cause for me it was always fast:)
– myxaxa
Nov 20 at 13:25
|
show 3 more comments
up vote
0
down vote
up vote
0
down vote
the main part the time is taken on is the get method and it's array_shift. you can use array_slice instead on 1000 elements for example:
<?php
class Item
{
protected $numbers = ;
public function add($number){
$this->numbers[$number] = true;
}
public function get(){
$x = key($this->numbers);
unset($this->numbers[$x]);
return $x;
}
}
ob_start();
$n = 50000;
$item = new Item();
$start = microtime(true);
for ($i=0; $i < $n ; $i++) {
$item->add("Test".$i);
}
echo microtime(true)-$start;
echo "rn";
$start = microtime(true);
for ($i=0; $i < $n ; $i++) {
echo $item->get() . "rn";
}
echo microtime(true)-$start;
ob_end_flush();
the main part the time is taken on is the get method and it's array_shift. you can use array_slice instead on 1000 elements for example:
<?php
class Item
{
protected $numbers = ;
public function add($number){
$this->numbers[$number] = true;
}
public function get(){
$x = key($this->numbers);
unset($this->numbers[$x]);
return $x;
}
}
ob_start();
$n = 50000;
$item = new Item();
$start = microtime(true);
for ($i=0; $i < $n ; $i++) {
$item->add("Test".$i);
}
echo microtime(true)-$start;
echo "rn";
$start = microtime(true);
for ($i=0; $i < $n ; $i++) {
echo $item->get() . "rn";
}
echo microtime(true)-$start;
ob_end_flush();
edited Nov 20 at 13:47
answered Nov 20 at 11:29
myxaxa
53736
53736
Yes, that is correct 0.082641124725342, 0.18116903305054. But you forgot to print the numbers. When you change to echo $item->get()."n", execution time is 14.767911911011.
– MajklRS
Nov 20 at 11:43
A small note, every time the number is requested, it is necessary to remove it from the queue.
– MajklRS
Nov 20 at 11:49
are you running it via cli or via browser? I suppose that 14 extra seconds come from the tcp the data is transferred by when you use browser :)
– myxaxa
Nov 20 at 11:53
I am running it from cli.
– MajklRS
Nov 20 at 12:07
so, I've updated the post - can you test again pls? cause for me it was always fast:)
– myxaxa
Nov 20 at 13:25
|
show 3 more comments
Yes, that is correct 0.082641124725342, 0.18116903305054. But you forgot to print the numbers. When you change to echo $item->get()."n", execution time is 14.767911911011.
– MajklRS
Nov 20 at 11:43
A small note, every time the number is requested, it is necessary to remove it from the queue.
– MajklRS
Nov 20 at 11:49
are you running it via cli or via browser? I suppose that 14 extra seconds come from the tcp the data is transferred by when you use browser :)
– myxaxa
Nov 20 at 11:53
I am running it from cli.
– MajklRS
Nov 20 at 12:07
so, I've updated the post - can you test again pls? cause for me it was always fast:)
– myxaxa
Nov 20 at 13:25
Yes, that is correct 0.082641124725342, 0.18116903305054. But you forgot to print the numbers. When you change to echo $item->get()."n", execution time is 14.767911911011.
– MajklRS
Nov 20 at 11:43
Yes, that is correct 0.082641124725342, 0.18116903305054. But you forgot to print the numbers. When you change to echo $item->get()."n", execution time is 14.767911911011.
– MajklRS
Nov 20 at 11:43
A small note, every time the number is requested, it is necessary to remove it from the queue.
– MajklRS
Nov 20 at 11:49
A small note, every time the number is requested, it is necessary to remove it from the queue.
– MajklRS
Nov 20 at 11:49
are you running it via cli or via browser? I suppose that 14 extra seconds come from the tcp the data is transferred by when you use browser :)
– myxaxa
Nov 20 at 11:53
are you running it via cli or via browser? I suppose that 14 extra seconds come from the tcp the data is transferred by when you use browser :)
– myxaxa
Nov 20 at 11:53
I am running it from cli.
– MajklRS
Nov 20 at 12:07
I am running it from cli.
– MajklRS
Nov 20 at 12:07
so, I've updated the post - can you test again pls? cause for me it was always fast:)
– myxaxa
Nov 20 at 13:25
so, I've updated the post - can you test again pls? cause for me it was always fast:)
– myxaxa
Nov 20 at 13:25
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391510%2flarger-simulation-of-adding-and-removing-items-from-queue-in-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what php version are you using and what is your pc config:) 'cause with the array_shift implementation I've got this result for add and get - 0.044579982757568 3.9010820388794
– myxaxa
Nov 20 at 11:15
PHP 7.1.16 on Macbook Pro 2011, i5, 8GB RAM. We also get that result when nothing is printed. If method get returns the number that is removed from the list and echo/print then the time increases.
– MajklRS
Nov 20 at 11:20
yeah, of course the get method is the heaviest one - cause array_shift is fat method. u can improve it as to use array_slice on 1000 elements for example. I'll try to solve it now
– myxaxa
Nov 20 at 11:27