gettext-speedtest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
  3. print "This script must be run from the command line\n";
  4. exit();
  5. }
  6. define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
  7. define('GNUSOCIAL', true);
  8. define('STATUSNET', true); // compatibility
  9. require_once INSTALLDIR . '/scripts/commandline.inc';
  10. require_once INSTALLDIR . '/extlib/php-gettext/gettext.inc';
  11. common_init_locale("en_US");
  12. common_init_locale('fr');
  13. putenv("LANG=fr");
  14. putenv("LANGUAGE=fr");
  15. setlocale('fr.utf8');
  16. _setlocale('fr.utf8');
  17. _bindtextdomain("statusnet", INSTALLDIR . '/locale');
  18. _bindtextdomain("FeedSub", INSTALLDIR . '/plugins/FeedSub/locale');
  19. $times = 10000;
  20. $delta = array();
  21. $start = microtime(true);
  22. for($i = 0; $i < $times; $i++) {
  23. $result = _("Send");
  24. }
  25. $delta["_"] = array((microtime(true) - $start) / $times, $result);
  26. $start = microtime(true);
  27. for($i = 0; $i < $times; $i++) {
  28. $result = __("Send");
  29. }
  30. $delta["__"] = array((microtime(true) - $start) / $times, $result);
  31. $start = microtime(true);
  32. for($i = 0; $i < $times; $i++) {
  33. $result = dgettext("FeedSub", "Feeds");
  34. }
  35. $delta["dgettext"] = array((microtime(true) - $start) / $times, $result);
  36. $start = microtime(true);
  37. for($i = 0; $i < $times; $i++) {
  38. $result = _dgettext("FeedSub", "Feeds");
  39. }
  40. $delta["_dgettext"] = array((microtime(true) - $start) / $times, $result);
  41. $start = microtime(true);
  42. for($i = 0; $i < $times; $i++) {
  43. // TRANS: String in the gettext speed test script. Unimportant.
  44. $result = _m("Feeds");
  45. }
  46. $delta["_m"] = array((microtime(true) - $start) / $times, $result);
  47. $start = microtime(true);
  48. for($i = 0; $i < $times; $i++) {
  49. $result = fake("Feeds");
  50. }
  51. $delta["fake"] = array((microtime(true) - $start) / $times, $result);
  52. foreach ($delta as $func => $bits) {
  53. list($time, $result) = $bits;
  54. $ms = $time * 1000.0;
  55. printf("%10s %2.4fms %s\n", $func, $ms, $result);
  56. }
  57. function fake($str) {
  58. return $str;
  59. }