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