Page MenuHomePhabricator
Paste P9016

(An Untitled Masterwork)
ActivePublic

Authored by Jdforrester-WMF on Aug 30 2019, 9:57 PM.
<?php
$dataS = @file_get_contents( './foo.data' );
$dataJ = @file_get_contents( './foo.json' );
// file_put_contents( './foo.json', json_encode( unserialize( $dataS ), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) . "\n" );
function runS() {
global $dataS;
ob_start();
$t = microtime( true );
$i = 0;
while($i < 10000) {
unserialize( $dataS );
++$i;
}
$tmp = microtime(true) - $t;
ob_end_clean();
return $tmp;
}
// Test Source
function runJ() {
global $dataJ;
ob_start();
$t = microtime( true );
$i = 0;
while($i < 10000) {
json_decode( $dataJ );
++$i;
}
$tmp = microtime(true) - $t;
ob_end_clean();
return $tmp;
}
echo( 'Serial: ' . runS() . "\n" );
echo( 'JSON: ' . runJ() . "\n" );

Event Timeline