Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 6
n/a
0 / 0
CRAP
n/a
0 / 0
BenchLookup
n/a
0 / 0
n/a
0 / 0
3
n/a
0 / 0
 __construct
n/a
0 / 0
n/a
0 / 0
1
 execute
n/a
0 / 0
n/a
0 / 0
2
1<?php
2/**
3 * Copyright (C) 2018 Kunal Mehta <legoktm@debian.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18
19namespace MediaWiki\SecureLinkFixer;
20
21use MediaWiki\Maintenance\Benchmarker;
22use const RUN_MAINTENANCE_IF_MAIN;
23
24$IP = getenv( 'MW_INSTALL_PATH' );
25if ( $IP === false ) {
26    $IP = __DIR__ . '/../../..';
27}
28require_once "$IP/maintenance/includes/Benchmarker.php";
29
30/**
31 * Benchmark the current HSTSPreloadLookup implementation
32 *
33 * @codeCoverageIgnore
34 */
35class BenchLookup extends Benchmarker {
36    public function __construct() {
37        parent::__construct();
38        $this->addDescription( 'Benchmark for HSTSPreloadLookup' );
39        $this->requireExtension( 'SecureLinkFixer' );
40    }
41
42    public function execute() {
43        $lookup = $this->getServiceContainer()->getService( 'HSTSPreloadLookup' );
44        $domains = [
45            // Need to traverse up one domain to find it
46            'foobar.dev',
47            // Directly in map
48            'wikipedia.org',
49            // Need to traverse up one domain to not find it
50            'not-preloaded.com',
51            // Need to traverse up 6 domains to not find it
52            'pathological.case.that.is.not.preloaded.org',
53        ];
54        $benches = [];
55        foreach ( $domains as $domain ) {
56            $benches[] = [
57                'function' => [ $lookup, 'isPreloaded' ],
58                'args' => [ $domain ],
59            ];
60        }
61        $this->bench( $benches );
62    }
63}
64
65$maintClass = BenchLookup::class;
66require_once RUN_MAINTENANCE_IF_MAIN;