summaryrefslogtreecommitdiff
path: root/plugins/FeedSub/tests/gettext-speedtest.php
blob: 8bbdf5e899a4e2d8817a83ad67fac901db82952e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php

if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
    print "This script must be run from the command line\n";
    exit();
}

define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
define('STATUSNET', true);
define('LACONICA', true);

require_once INSTALLDIR . '/scripts/commandline.inc';
require_once INSTALLDIR . '/extlib/php-gettext/gettext.inc';

common_init_locale("en_US");
common_init_locale('fr');


putenv("LANG=fr");
putenv("LANGUAGE=fr");
setlocale('fr.utf8');
_setlocale('fr.utf8');

_bindtextdomain("statusnet", INSTALLDIR . '/locale');
_bindtextdomain("FeedSub", INSTALLDIR . '/plugins/FeedSub/locale');

$times = 10000;
$delta = array();

$start = microtime(true);
for($i = 0; $i < $times; $i++) {
    $result = _("Send");
}
$delta["_"] = array((microtime(true) - $start) / $times, $result);

$start = microtime(true);
for($i = 0; $i < $times; $i++) {
    $result = __("Send");
}
$delta["__"] = array((microtime(true) - $start) / $times, $result);

$start = microtime(true);
for($i = 0; $i < $times; $i++) {
    $result = dgettext("FeedSub", "Feeds");
}
$delta["dgettext"] = array((microtime(true) - $start) / $times, $result);

$start = microtime(true);
for($i = 0; $i < $times; $i++) {
    $result = _dgettext("FeedSub", "Feeds");
}
$delta["_dgettext"] = array((microtime(true) - $start) / $times, $result);


$start = microtime(true);
for($i = 0; $i < $times; $i++) {
    $result = _m("Feeds");
}
$delta["_m"] = array((microtime(true) - $start) / $times, $result);


$start = microtime(true);
for($i = 0; $i < $times; $i++) {
    $result = fake("Feeds");
}
$delta["fake"] = array((microtime(true) - $start) / $times, $result);

foreach ($delta as $func => $bits) {
    list($time, $result) = $bits;
    $ms = $time * 1000.0;
    printf("%10s %2.4fms %s\n", $func, $ms, $result);
}


function fake($str) {
    return $str;
}