-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender-test.php
104 lines (81 loc) · 3.23 KB
/
render-test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
$matrix = array(
'compress' => array(
'raw' => '$string',
'snappy' => 'snappy_compress($string)',
'gzip-9' => 'gzcompress($string, 9)',
'gzip-6' => 'gzcompress($string, 6)',
'gzip-3' => 'gzcompress($string, 3)',
'gzip-1' => 'gzcompress($string, 1)',
),
'decompress' => array(
'raw' => '$string',
'snappy' => 'snappy_uncompress($string)',
'gzip-9' => 'gzuncompress($string)',
'gzip-6' => 'gzuncompress($string)',
'gzip-3' => 'gzuncompress($string)',
'gzip-1' => 'gzuncompress($string)',
),
'serialize' => array(
'serialize' => 'serialize($data)',
'json' => 'json_encode($data)',
'igbinary' => 'igbinary_serialize($data)',
'msgpack' => 'msgpack_pack($data)',
),
'unserialize' => array(
'serialize' => 'unserialize($data)',
'json' => 'json_decode($data, true)',
'igbinary' => 'igbinary_unserialize($data)',
'msgpack' => 'msgpack_unpack($data)',
),
);
if (!function_exists('snappy_compress')) {
unset($matrix['compress']['snappy']);
unset($matrix['decompress']['snappy']);
}
if (!function_exists('gzcompress')) {
unset($matrix['compress']['gzip-9']);
unset($matrix['decompress']['gzip-9']);
unset($matrix['compress']['gzip-6']);
unset($matrix['decompress']['gzip-6']);
unset($matrix['compress']['gzip-3']);
unset($matrix['decompress']['gzip-3']);
unset($matrix['compress']['gzip-1']);
unset($matrix['decompress']['gzip-1']);
}
if (!function_exists('igbinary_serialize')) {
unset($matrix['serialize']['igbinary']);
unset($matrix['unserialize']['igbinary']);
}
if (!function_exists('msgpack_pack')) {
unset($matrix['serialize']['msgpack']);
unset($matrix['unserialize']['msgpack']);
}
ob_start();
$script = '<?php' . PHP_EOL;
foreach ($matrix['compress'] as $compressType => $compress) {
foreach ($matrix['serialize'] as $serializeType => $serialize) {
$unserialize = $matrix['unserialize'][$serializeType];
$decompress = $matrix['decompress'][$compressType];
?>
$start = microtime(1);
//$mem_start = memory_get_usage();
for ($i = 0;$i < $iterationsCount;++$i) {
//$tmp = $compress($serialize($data)));
$tmp = <?php echo str_replace('$string', $serialize, $compress)?>;
}
$stat['encode']['<?php echo $compressType?>/<?php echo $serializeType?>'] = 1000 * (microtime(1) - $start);
$tmp = <?php echo str_replace('$string', $serialize, $compress)?>;
$stat['length']['<?php echo $compressType?>/<?php echo $serializeType?>'] = strlen($tmp);
$start = microtime(1);
for ($i = 0;$i < $iterationsCount;++$i) {
//$tmp2 = $unserialize($decompress($tmp));
$tmp2 = <?php echo str_replace('$data', str_replace('$string', '$tmp', $decompress), $unserialize)?>;
}
$stat['decode']['<?php echo $compressType?>/<?php echo $serializeType?>'] = 1000 * (microtime(1) - $start);
//$stat['mem_usage']['<?php echo $compressType?>/<?php echo $serializeType?>'] = memory_get_usage() - $mem_start;
<?php
}
}
$script .= ob_get_clean();
file_put_contents('test.php', $script);