29 require __DIR__ .
'/../CommandLineInc.php';
31 if ( !isset(
$args[0] ) ) {
32 echo
"Usage: php testCompression.php [--type=<type>] [--start=<start-date>] " .
33 "[--limit=<num-revs>] <page-title>\n";
37 $lang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage(
'en' );
39 if ( isset( $options[
'start'] ) ) {
40 $start =
wfTimestamp( TS_MW, strtotime( $options[
'start'] ) );
41 echo
"Starting from " .
$lang->timeanddate( $start ) .
"\n";
43 $start =
'19700101000000';
45 if ( isset( $options[
'limit'] ) ) {
46 $limit = $options[
'limit'];
52 $type = $options[
'type'] ?? ConcatenatedGzipHistoryBlob::class;
55 $revStore = MediaWikiServices::getInstance()->getRevisionStore();
61 'page_namespace' =>
$title->getNamespace(),
62 'page_title' =>
$title->getDBkey(),
63 'rev_timestamp > ' .
$dbr->addQuotes(
$dbr->timestamp( $start ) ),
66 [
'LIMIT' => $limit ],
74 $t = -microtime(
true );
75 foreach (
$res as $row ) {
76 $revRecord =
$revStore->newRevisionFromRow( $row );
77 $text = $revRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )
81 $hashes[$row->rev_id] = md5( $text );
89 $t += microtime(
true );
90 # print_r( $blob->mDiffMap );
92 printf(
"%s\nCompression ratio for %d revisions: %5.2f, %s -> %d\n",
99 printf(
"Compression time: %5.2f ms\n",
$t * 1000 );
101 $t = -microtime(
true );
103 foreach (
$keys as $id => $key ) {
104 $text =
$blob->getItem( $key );
105 if ( md5( $text ) !=
$hashes[$id] ) {
106 echo
"Content hash mismatch for rev_id $id\n";
110 $t += microtime(
true );
111 printf(
"Decompression time: %5.2f ms\n",
$t * 1000 );