-
Notifications
You must be signed in to change notification settings - Fork 5
/
benchmark.php
57 lines (41 loc) · 1.21 KB
/
benchmark.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
<?php
$json = file_get_contents("test.json");
echo('json.len = '.strlen($json)."\n");
////////////////////////////////////////
$times = 1000;
$start_time = microtime(true);
$start_mem = memory_get_usage();
/*$r = new Rapidjson($json);
foreach ($r as $k => $v) {
echo $k."\n";
}
*/
for($i = 0; $i < $times; $i++) {
$r = new Rapidjson($json);
$r['gsid'] = 'memeda';
$newjson = $r->__toString();
}
var_dump($r['gsid']);
file_put_contents("rapidjson.json", $newjson);
echo('newjson.len = '.strlen($newjson)."\n");
$end_time = microtime(true);
$end_mem = memory_get_usage();
echo "Rapidjson.time: " . ($end_time - $start_time)."\n";
echo "Rapidjson.mem: " . ($end_mem - $start_mem)."\n";
/////////////////////////////////////
$start_time = microtime(true);
$start_mem = memory_get_usage();
$newjson = "";
for($i = 0; $i < $times; $i++) {
$r = json_decode($json);
$r->gsid = 'memeda';
$newjson = json_encode($r);
}
var_dump($r->gsid);
file_put_contents("json_decode.json", $newjson);
echo('newjson.len = '.strlen($newjson)."\n");
$end_time = microtime(true);
$end_mem = memory_get_usage();
echo "json_decode.time: " . ($end_time - $start_time)."\n";
echo "json_decode.mem: " . ($end_mem - $start_mem)."\n";
?>