Created
April 23, 2017 16:09
-
-
Save thekid/4a3e9f5b51aa140218468ca8b922d223 to your computer and use it in GitHub Desktop.
Performance profiling for xp-framework/collections#1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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