StripNullBytes.php 776 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * @package koseven/Codebench
  4. * @category Tests
  5. * @author Geert De Deckere <geert@idoe.be>
  6. */
  7. class Bench_StripNullBytes extends Codebench {
  8. public $description =
  9. 'String replacement comparisons related to <a href="http://github.com/koseven/koseven/issues/2676">#2676</a>.';
  10. public $loops = 1000;
  11. public $subjects = [
  12. "\0",
  13. "\0\0\0\0\0\0\0\0\0\0",
  14. "bla\0bla\0bla\0bla\0bla\0bla\0bla\0bla\0bla\0bla",
  15. "blablablablablablablablablablablablablablablabla",
  16. ];
  17. public function bench_str_replace($subject)
  18. {
  19. return str_replace("\0", '', $subject);
  20. }
  21. public function bench_strtr($subject)
  22. {
  23. return strtr($subject, ["\0" => '']);
  24. }
  25. public function bench_preg_replace($subject)
  26. {
  27. return preg_replace('~\0+~', '', $subject);
  28. }
  29. }