3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
19 * @ingroup Maintenance
20 * @see wfWaitForSlaves()
23 $optionsWithArgs = array( 'start', 'limit', 'type' );
24 require( dirname( __FILE__
) . '/../commandLine.inc' );
26 if ( !isset( $args[0] ) ) {
27 echo "Usage: php testCompression.php [--type=<type>] [--start=<start-date>] [--limit=<num-revs>] <page-title>\n";
31 $title = Title
::newFromText( $args[0] );
32 if ( isset( $options['start'] ) ) {
33 $start = wfTimestamp( TS_MW
, strtotime( $options['start'] ) );
34 echo "Starting from " . $wgLang->timeanddate( $start ) . "\n";
36 $start = '19700101000000';
38 if ( isset( $options['limit'] ) ) {
39 $limit = $options['limit'];
45 $type = isset( $options['type'] ) ?
$options['type'] : 'ConcatenatedGzipHistoryBlob';
48 $dbr = wfGetDB( DB_SLAVE
);
50 array( 'page', 'revision', 'text' ),
53 'page_namespace' => $title->getNamespace(),
54 'page_title' => $title->getDBkey(),
56 'rev_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $start ) ),
58 ), __FILE__
, array( 'LIMIT' => $limit )
64 $uncompressedSize = 0;
65 $t = -microtime( true );
66 foreach ( $res as $row ) {
67 $revision = new Revision( $row );
68 $text = $revision->getText();
69 $uncompressedSize +
= strlen( $text );
70 $hashes[$row->rev_id
] = md5( $text );
71 $keys[$row->rev_id
] = $blob->addItem( $text );
72 if ( $untilHappy && !$blob->isHappy() ) {
77 $serialized = serialize( $blob );
78 $t +
= microtime( true );
79 # print_r( $blob->mDiffMap );
81 printf( "%s\nCompression ratio for %d revisions: %5.2f, %s -> %d\n",
84 $uncompressedSize / strlen( $serialized ),
85 $wgLang->formatSize( $uncompressedSize ),
88 printf( "Compression time: %5.2f ms\n", $t * 1000 );
90 $t = -microtime( true );
91 $blob = unserialize( $serialized );
92 foreach ( $keys as $id => $key ) {
93 $text = $blob->getItem( $key );
94 if ( md5( $text ) != $hashes[$id] ) {
95 echo "Content hash mismatch for rev_id $id\n";
99 $t +
= microtime( true );
100 printf( "Decompression time: %5.2f ms\n", $t * 1000 );