summaryrefslogtreecommitdiffstats
path: root/utils/testQuerySpeed.php
blob: 6082864198a050285a8d9c7c41d689e3eed11a55 (plain) (blame)
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
<?php

/**
 * Test speed of query
 * Uroš Podkrižnik 21.12.2017
 */
class testQuerySpeed {

    function __construct() {
        
    }

    function test($sql_query = "SELECT id FROM srv_anketa", $loopnum = 1000) {
        $microa = 0;
        $microo = 0;
        $microni = 0;
        $micron = 0;
        for ($i = 0; $i < $loopnum; $i++) {
            $starta = microtime(true);
            $sql_array = sisplet_query($sql_query, 'array');
            foreach ($sql_array as $pair)
                $res = $pair;
            $enda = microtime(true);
            $microa += ($enda - $starta);

            $starto = microtime(true);
            $sql_obj = sisplet_query($sql_query, 'obj');
            foreach ($sql_obj as $pair)
                $res = $pair;
            $endo = microtime(true);
            $microo += ($endo - $starto);

            $startn = microtime(true);
            $sql = sisplet_query($sql_query);
            while ($row = mysqli_fetch_assoc($sql))
                $res = $row;
            $endn = microtime(true);
            $microni += ($endn - $startn);

            $startn = microtime(true);
            $sql = sisplet_query($sql_query);
            while ($row = mysqli_fetch_assoc($sql))
                $res = $row;
            $endn = microtime(true);
            $micron += ($endn - $startn);
        }
        error_log('$microa ' . $microa);
        error_log('$microo ' . $microo);
        error_log('$microni ' . $microni);
        error_log('$micron ' . $micron);
    }

}