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 = [];
  21. $start = hrtime(true);
  22. for ($i = 0; $i < $times; ++$i) {
  23. $result = _('Send');
  24. }
  25. $delta['_'] = [(hrtime(true) - $start) / $times, $result];
  26. $start = hrtime(true);
  27. for ($i = 0; $i < $times; ++$i) {
  28. $result = __('Send');
  29. }
  30. $delta['__'] = [(hrtime(true) - $start) / $times, $result];
  31. $start = hrtime(true);
  32. for ($i = 0; $i < $times; ++$i) {
  33. $result = dgettext('FeedSub', 'Feeds');
  34. }
  35. $delta['dgettext'] = [(hrtime(true) - $start) / $times, $result];
  36. $start = hrtime(true);
  37. for ($i = 0; $i < $times; ++$i) {
  38. $result = _dgettext('FeedSub', 'Feeds');
  39. }
  40. $delta['_dgettext'] = [(hrtime(true) - $start) / $times, $result];
  41. $start = hrtime(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'] = [(hrtime(true) - $start) / $times, $result];
  47. $start = hrtime(true);
  48. for ($i = 0; $i < $times; ++$i) {
  49. $result = fake('Feeds');
  50. }
  51. $delta['fake'] = [(hrtime(true) - $start) / $times, $result];
  52. foreach ($delta as $func => $bits) {
  53. [$time, $result] = $bits;
  54. $ms = $time / 1000000;
  55. printf("%10s %2.4fms %s\n", $func, $ms, $result);
  56. }
  57. function fake(string $str)
  58. {
  59. return $str;
  60. }