Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $segment = 10000;
- $maxValue = 10000;
- for($j = 1; $j < 10; $j++)
- {
- $operations = $segment*$j;
- $size = 0;
- $set = new HashSet();
- $start = microtime(true);
- for($i = 0; $i < $operations; $i++)
- {
- $value = rand(1, $maxValue);
- if($set->add($value))
- {
- $size++;
- }
- }
- $end = microtime(true);
- echo $size;
- $duration = ($end-$start)*1000;
- echo "\nHashSet: {$operations}, {$duration}";
- $arraySet = [];
- $size = 0;
- $start = microtime(true);
- for($i = 0; $i < $operations; $i++)
- {
- $value = rand(1, $maxValue);
- if(!in_array($value, $arraySet))
- {
- $arraySet[] = $value;
- $size++;
- }
- }
- $end = microtime(true);
- $duration = ($end-$start)*1000;
- echo "\narray {$operations}, {$duration}";
- $ice = new Set();
- $size = 0;
- $start = microtime(true);
- for($i = 0; $i < $operations; $i++)
- {
- $value = rand(1, $maxValue);
- if($ice->add($value))
- {
- $size++;
- }
- }
- $end = microtime(true);
- $this->assertEquals($size, $ice->size());
- $duration = ($end-$start)*1000;
- echo "\nIce: {$operations}, {$duration}";
- }
Advertisement
Add Comment
Please, Sign In to add comment