Skip to content

Instantly share code, notes, and snippets.

@thekid
Created April 23, 2017 16:09
Show Gist options
  • Select an option

  • Save thekid/4a3e9f5b51aa140218468ca8b922d223 to your computer and use it in GitHub Desktop.

Select an option

Save thekid/4a3e9f5b51aa140218468ca8b922d223 to your computer and use it in GitHub Desktop.
Performance profiling for xp-framework/collections#1
<?php
use util\collections\{HashTable, HashSet, Queue, Stack};
class Collections extends \util\profiling\Measurable {
#[@measure]
public function hashTable() {
$h= new HashTable();
$h->put('key', 'value');
$h->put('color', 'green');
if ($h->containsKey('color')) {
$h->remove('color');
}
return $h->get('key', 'value');
}
#[@measure]
public function hashSet() {
$h= new HashSet();
$h->add('key');
$h->add('color');
if ($h->contains('color')) {
$h->remove('color');
}
return $h->size();
}
#[@measure]
public function queue() {
$q= new Queue();
$q->put('value');
$q->put('green');
if ($element= $q->peek()) {
$q->remove($element);
}
return $q->get();
}
#[@measure]
public function stack() {
$q= new Stack();
$q->push('value');
$q->push('green');
return $q->pop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment