diff options
| author | Hideyuki TAKEI <takehide22@gmail.com> | 2010-04-05 00:10:28 +0900 |
|---|---|---|
| committer | Hideyuki TAKEI <takehide22@gmail.com> | 2010-04-05 00:10:28 +0900 |
| commit | 99a2d2859269ddf803a802c043babcd977260faf (patch) | |
| tree | 5d0a89a77fab9f3c81dbcf49ef5696ef6d3b1f26 /php/bench | |
| parent | 254ee80c16b3b0ce12b461d189aa1e6302debea0 (diff) | |
| download | msgpack-python-99a2d2859269ddf803a802c043babcd977260faf.tar.gz | |
import MessagePack for PHP
Diffstat (limited to 'php/bench')
| -rw-r--r-- | php/bench/bench.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/php/bench/bench.php b/php/bench/bench.php new file mode 100644 index 0000000..95a7ca4 --- /dev/null +++ b/php/bench/bench.php @@ -0,0 +1,51 @@ +<?php + +//ini_set('memory_limit' ,'128M'); + +$ary = array(); +for($i=0; $i<pow(2, 10); $i++){ + $ary = array_merge($ary, range(0, 1024)); +} + +echo count($ary); + +function getSize($ary) +{ + if (ini_get('mbstring.func_overload') & 2 && function_exists('mb_strlen')) { + $size = mb_strlen($ary, 'ASCII'); + } else { + $size = strlen($ary); + } + + return $size; +} + +echo "fin" . $size . "\n"; + +echo "----\n"; +echo "MessagePack\n"; +$a = microtime(true); +$packed = msgpack_pack($ary); +$b = microtime(true); +echo ($b-$a) . "sec, " . getSize($packed) . "bytes\n"; + +$a = microtime(true); +$pack = msgpack_unpack($packed); +$b = microtime(true); +echo ($b-$a) . "sec\n"; + + +echo "----\n"; +echo "JSON\n"; +$a = microtime(true); +$jsoned = json_encode($ary); +$b = microtime(true); +echo ($b-$a) . "sec, " . getSize($jsoned) . "bytes\n"; + +$a = microtime(true); +$json = json_decode($jsoned); +$b = microtime(true); +echo ($b-$a) . "sec\n"; + + +?> |
