PageRenderTime 55ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/maintenance/benchmarks/bench_strtr_str_replace.php

https://github.com/spenser-roark/OOUG-Wiki
PHP | 54 lines | 37 code | 13 blank | 4 comment | 1 complexity | e87b14aa00586555c5c762e8a2ec4753 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, LGPL-3.0
  1. <?php
  2. /**
  3. * @file
  4. * @ingroup Benchmark
  5. */
  6. require_once( dirname( __FILE__ ) . '/Benchmarker.php' );
  7. function bfNormalizeTitleStrTr( $str ) {
  8. return strtr( $str, '_', ' ' );
  9. }
  10. function bfNormalizeTitleStrReplace( $str ) {
  11. return str_replace( '_', ' ', $str );
  12. }
  13. class bench_strtr_str_replace extends Benchmarker {
  14. public function __construct() {
  15. parent::__construct();
  16. $this->mDescription = "Benchmark for strtr() vs str_replace().";
  17. }
  18. public function execute() {
  19. $this->bench( array(
  20. array( 'function' => array( $this, 'benchstrtr' ) ),
  21. array( 'function' => array( $this, 'benchstr_replace' ) ),
  22. array( 'function' => array( $this, 'benchstrtr_indirect' ) ),
  23. array( 'function' => array( $this, 'benchstr_replace_indirect' ) ),
  24. ));
  25. print $this->getFormattedResults();
  26. }
  27. function benchstrtr() {
  28. strtr( "[[MediaWiki:Some_random_test_page]]", "_", " " );
  29. }
  30. function benchstr_replace() {
  31. str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]");
  32. }
  33. function benchstrtr_indirect() {
  34. bfNormalizeTitleStrTr( "[[MediaWiki:Some_random_test_page]]" );
  35. }
  36. function benchstr_replace_indirect() {
  37. bfNormalizeTitleStrReplace( "[[MediaWiki:Some_random_test_page]]" );
  38. }
  39. }
  40. $maintClass = 'bench_strtr_str_replace';
  41. require_once( RUN_MAINTENANCE_IF_MAIN );