3 $optionsWithArgs = array( 'start', 'limit', 'type' );
4 require( dirname( __FILE__
) . '/../commandLine.inc' );
6 if ( !isset( $args[0] ) ) {
7 echo "Usage: php testCompression.php [--type=<type>] [--start=<start-date>] [--limit=<num-revs>] <page-title>\n";
11 $title = Title
::newFromText( $args[0] );
12 if ( isset( $options['start'] ) ) {
13 $start = wfTimestamp( TS_MW
, strtotime( $options['start'] ) );
14 echo "Starting from " . $wgLang->timeanddate( $start ) . "\n";
16 $start = '19700101000000';
18 if ( isset( $options['limit'] ) ) {
19 $limit = $options['limit'];
25 $type = isset( $options['type'] ) ?
$options['type'] : 'ConcatenatedGzipHistoryBlob';
28 $dbr = wfGetDB( DB_SLAVE
);
30 array( 'page', 'revision', 'text' ),
33 'page_namespace' => $title->getNamespace(),
34 'page_title' => $title->getDBkey(),
36 'rev_timestamp > ' . $dbr->addQuotes( $dbr->timestamp( $start ) ),
38 ), __FILE__
, array( 'LIMIT' => $limit )
44 $uncompressedSize = 0;
45 $t = -microtime( true );
46 foreach ( $res as $row ) {
47 $revision = new Revision( $row );
48 $text = $revision->getText();
49 $uncompressedSize +
= strlen( $text );
50 $hashes[$row->rev_id
] = md5( $text );
51 $keys[$row->rev_id
] = $blob->addItem( $text );
52 if ( $untilHappy && !$blob->isHappy() ) {
57 $serialized = serialize( $blob );
58 $t +
= microtime( true );
59 # print_r( $blob->mDiffMap );
61 printf( "%s\nCompression ratio for %d revisions: %5.2f, %s -> %d\n",
64 $uncompressedSize / strlen( $serialized ),
65 $wgLang->formatSize( $uncompressedSize ),
68 printf( "Compression time: %5.2f ms\n", $t * 1000 );
70 $t = -microtime( true );
71 $blob = unserialize( $serialized );
72 foreach ( $keys as $id => $key ) {
73 $text = $blob->getItem( $key );
74 if ( md5( $text ) != $hashes[$id] ) {
75 echo "Content hash mismatch for rev_id $id\n";
79 $t +
= microtime( true );
80 printf( "Decompression time: %5.2f ms\n", $t * 1000 );