Skip to content

Instantly share code, notes, and snippets.

@lav45
Last active September 28, 2016 20:22
Show Gist options
  • Save lav45/468bb1e7928b88ea2ed37c4a6bb4986c to your computer and use it in GitHub Desktop.
Save lav45/468bb1e7928b88ea2ed37c4a6bb4986c to your computer and use it in GitHub Desktop.
benchmark Judy
<?php
/**
* PHP 7.0.11-1+deb.sury.org~trusty+1 (cli) ( NTS )
* Copyright (c) 1997-2016 The PHP Group
* Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
* with Zend OPcache v7.0.11-1+deb.sury.org~trusty+1, Copyright (c) 1999-2016, by Zend Technologies
* with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans
*
* extension Judy => https://github.com/tony2001/php-judy/tree/php7
*/
$memory = -memory_get_usage(true);
$time = -microtime(true);
$arr = []; // 1.325s 512Mb
// $arr = new Judy(Judy::STRING_TO_MIXED); // 3.548s 152Mb
// $arr = new Judy(Judy::INT_TO_MIXED); // 2.233s 152Mb
for ($i = 0; $i < 10000000; $i++) {
$arr[$i] = true;
}
$time += microtime(true);
$memory += memory_get_usage(true);
echo
"memory:\t" . convert($memory) . "\n" .
"time:\t" . round($time, 3) . "s\n" ;
function convert($size)
{
$i = floor(log($size, 1024));
$unit = ['b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb'];
return @round($size / pow(1024, $i), 2) . $unit[$i];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment