summaryrefslogtreecommitdiff
path: root/tests/compare/serialize-v-jsonencode.php
blob: c66c21be7448da6e619910756bb64aa9cc0aef96 (plain)
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
<?php
echo "test started... ";
ob_flush();

Benchmark::add_spot('query-10000-products');
$db = Registry::use('database');
$products = $db->runQuery("SELECT * FROM products LIMIT 10000",[]);

Benchmark::add_spot('serialize-start');
foreach($products as $product) {
    $ser = serialize($product);
}

Benchmark::add_spot('serialize+unserialize-start');
foreach($products as $product) {
    $ser = serialize($product);
    $ori = unserialize($ser);
}

Benchmark::add_spot('jsonencode-start');
foreach($products as $product) {
    $json = json_encode($product);
}

Benchmark::add_spot('jsonencode+decode-start');
foreach($products as $product) {
    $json = json_encode($product);
    $ori = json_decode($json);
}

Benchmark::add_spot('end');
echo(Benchmark::report(BENCH_REPORT_COMMENT));
echo "test completed!";

die();