Last active
December 15, 2015 19:08
-
-
Save thekid/5308590 to your computer and use it in GitHub Desktop.
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\profiling\Timer; | |
| use \lang\Runtime; | |
| class EndsWithTest extends Object { | |
| public static function main($args) { | |
| foreach (['not-contained', 'contained'] as $needle) { | |
| foreach (['', 'Hello runners', file_get_contents(__FILE__), file_get_contents('README.md')] as $haystack) { | |
| $haystack.= 'contained'; | |
| $t= Timer::measure(function() use($needle, $haystack) { | |
| $s= new String($haystack); | |
| for ($i= 0; $i < 50000; $i++) { | |
| $s->endsWith($needle); | |
| } | |
| }); | |
| Console::writeLinef( | |
| '"%s": %d bytes: %.3f seconds, memory used: %.3f kB', | |
| $needle, | |
| strlen($haystack), | |
| $t->elapsedTime(), | |
| Runtime::getInstance()->memoryUsage() / 1024 | |
| ); | |
| } | |
| } | |
| } | |
| } | |
| ?> |
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\profiling\Timer; | |
| use \lang\Runtime; | |
| class StartsWithTest extends Object { | |
| public static function main($args) { | |
| foreach (['not-contained', 'contained'] as $needle) { | |
| foreach (['', 'Hello runners', file_get_contents(__FILE__), file_get_contents('README.md')] as $haystack) { | |
| $haystack= 'contained'.$haystack; | |
| $t= Timer::measure(function() use($needle, $haystack) { | |
| $s= new String($haystack); | |
| for ($i= 0; $i < 50000; $i++) { | |
| $s->startsWith($needle); | |
| } | |
| }); | |
| Console::writeLinef( | |
| '"%s": %d bytes: %.3f seconds, memory used: %.3f kB', | |
| $needle, | |
| strlen($haystack), | |
| $t->elapsedTime(), | |
| Runtime::getInstance()->memoryUsage() / 1024 | |
| ); | |
| } | |
| } | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment