Skip to content

Instantly share code, notes, and snippets.

@thekid
Last active December 15, 2015 19:08
Show Gist options
  • Select an option

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

Select an option

Save thekid/5308590 to your computer and use it in GitHub Desktop.
<?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
);
}
}
}
}
?>
<?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