|
| 1 | +<?php |
| 2 | + |
| 3 | +ini_set('memory_limit', '32G'); |
| 4 | + |
| 5 | + |
| 6 | +// PARFS speed test |
| 7 | + |
| 8 | +echo "PHP Version: ".phpversion()." @ ".gethostname()."\n"; |
| 9 | + |
| 10 | +$sz = function ($f, $fu, $data, $iterations=10, $gz=1) { |
| 11 | + $raw_size = 0; |
| 12 | + $t0 = microtime(1); |
| 13 | + foreach (range(1, $iterations) as $XX) { |
| 14 | + if ($f == 'json_encode') |
| 15 | + $y = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
| 16 | + else |
| 17 | + $y = $f($data); |
| 18 | + if (! $raw_size) |
| 19 | + $raw_size = strlen($y); |
| 20 | + if ($gz) |
| 21 | + $y = gzdeflate($y); |
| 22 | + } |
| 23 | + $time = microtime(1) - $t0; |
| 24 | + $zip_size = strlen($y); |
| 25 | + |
| 26 | + $t0 = microtime(1); |
| 27 | + foreach (range(1, $iterations) as $XX) { |
| 28 | + if ($gz) |
| 29 | + $z = gzinflate($y); |
| 30 | + else |
| 31 | + $z = $y; |
| 32 | + if ($f == 'json_encode') |
| 33 | + $z = json_decode($z, 1); |
| 34 | + #elseif ($f == 'serialize') |
| 35 | + # $z = unserialize(gzinflate($y), false); // PHP7 ONLY |
| 36 | + else |
| 37 | + $z = $fu($z); |
| 38 | + } |
| 39 | + $time2 = microtime(1) - $t0; |
| 40 | + |
| 41 | + return str_pad($f.":", 20). |
| 42 | + " ".str_pad(number_format($raw_size), 10, " ",STR_PAD_LEFT). |
| 43 | + " ".str_pad(number_format($zip_size), 10, " ",STR_PAD_LEFT). |
| 44 | + " ".str_pad(number_format($time2 / $iterations, 4), 9, " ",STR_PAD_LEFT). |
| 45 | + " ".str_pad(number_format($time / $iterations, 4), 10, " ",STR_PAD_LEFT); |
| 46 | +}; |
| 47 | + |
| 48 | + |
| 49 | +$size = 1500; |
| 50 | +$data = []; |
| 51 | +for($i=0; $i<$size; $i++){ |
| 52 | + for($j=0; $j<$size; $j++){ |
| 53 | + $data[$i][$j] = [$i, "a$i" => "b$j"]; |
| 54 | + } |
| 55 | +} |
| 56 | +$data_set = "array $size x $size"; |
| 57 | + |
| 58 | +$iterations = 2; |
| 59 | +$mem = number_format(memory_get_peak_usage(1) / 1000000, 1); |
| 60 | +echo "Data set: `$data_set`, performed $iterations iterations, data-set-memory-usage: ${mem}M\n", |
| 61 | + "ALGO SIZE-RAW SIZE-GZIP UNPACK1/sec PACK1/sec << time per one iteration", "\n", |
| 62 | +# $sz("igbinary_serialize", "igbinary_unserialize", $data, $iterations), "\n", |
| 63 | + $sz("igbinary_serialize", "igbinary_unserialize", $data, $iterations, 0), "\n", |
| 64 | +# $sz("msgpack_pack", "msgpack_unpack", $data, $iterations), "\n", |
| 65 | + $sz("msgpack_pack", "msgpack_unpack", $data, $iterations, 0), "\n" |
| 66 | +# $sz("json_encode", "json_decode", $sd), |
| 67 | +# $sz("serialize", "unserialize", $sd) |
| 68 | +; |
| 69 | + |
| 70 | +/* |
| 71 | + RESULTS: |
| 72 | + |
| 73 | + > ./igbinary-vs-msgpack.php |
| 74 | +PHP Version: 5.6.20 @ |
| 75 | +Data set: `array 1500 x 1500`, performed 2 iterations, data-set-memory-usage: 1,306.0M |
| 76 | +ALGO SIZE-RAW SIZE-GZIP UNPACK1/sec PACK1/sec << time per one iteration |
| 77 | +igbinary_serialize: 34,866,787 34,866,787 1.8073 2.1464 |
| 78 | +msgpack_pack: 34,348,503 34,348,503 51.9373 1.3356 |
| 79 | +
|
| 80 | +> ./igbinary-vs-msgpack.php |
| 81 | +PHP Version: 7.0.8 @ |
| 82 | +Data set: `array 1500 x 1500`, performed 2 iterations, data-set-memory-usage: 1,101.0M |
| 83 | +ALGO SIZE-RAW SIZE-GZIP UNPACK1/sec PACK1/sec << time per one iteration |
| 84 | +igbinary_serialize: 34,866,787 34,866,787 3.3561 0.6330 |
| 85 | +msgpack_pack: 34,348,503 34,348,503 91.5198 1.6248 |
| 86 | +
|
| 87 | + |
| 88 | + */ |
| 89 | + |
0 commit comments