Passed
Branch master (337fd9)
by Richard
03:45 queued 01:06
created

benchmark.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/******************************************************************************
3
 * An iterator interface over the Leagues flysystem.
4
 * Copyright (c) 2021, 2015 Richard Klees <[email protected]>
5
 *
6
 * This software is licensed under GPLv3. You should have received
7
 * a copy of the along with the code.
8
 */
9
10
require_once("tests/autoloader.php");
11
12
$adapter = new \League\Flysystem\Adapter\Local(__DIR__);
13
$flysystem = new \League\Flysystem\Filesystem($adapter);
14
$flightcontrol_strict = new \Lechimp\Flightcontrol\Flightcontrol($flysystem);
15
16
$dir = $flightcontrol_strict->directory("");
17
18
$runs = 100;
19
$count = 0;
20
21
$start = microtime(true);
22
for ($i = 0; $i < $runs; $i++) {
23
    $count = 0;
24
    $dir
25
        ->iterateOn()
26
            ->iterateOn()
27
            ->with(function ($obj) use (&$count) {
0 ignored issues
show
The parameter $obj is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
                $count += 1;
29
            });
30
}
31
$end = microtime(true);
32
$diff = $end - $start;
33
34
echo "Flightcontrol: " . sprintf("%10.4f", $diff) . " s (and counted $count)\n";
35
36
$start = microtime(true);
37
for ($i = 0; $i < $runs; $i++) {
38
    $count = 0;
39
    foreach ($flysystem->listContents() as $dir) {
0 ignored issues
show
The call to listContents() misses a required argument $location.

This check looks for function calls that miss required arguments.

Loading history...
40
        foreach ($flysystem->listContents($dir["path"]) as $dir2) {
41
            $count += 1;
42
        }
43
    }
44
}
45
$end = microtime(true);
46
$diff = $end - $start;
47
48
echo "Flysystem:     " . sprintf("%10.4f", $diff) . " s (and counted $count)\n";
49
50
$start = microtime(true);
51
for ($i = 0; $i < $runs; $i++) {
52
    $count = 0;
53
    foreach (scandir(".") as $dir) {
54
        if (!is_dir($dir) or $dir == "." or $dir == "..") {
55
            continue;
56
        }
57
        foreach (scandir("./$dir") as $dir2) {
58
            if ($dir2 == "." or $dir2 == "..") {
59
                continue;
60
            }
61
            $count += 1;
62
        }
63
    }
64
}
65
$end = microtime(true);
66
$diff = $end - $start;
67
68
echo "scandir:       " . sprintf("%10.4f", $diff) . " s (and counted $count)\n";
69