def test_domain_lookup_sparse_benchmark(url, values, benchmark):
    blocked_hosts = os.path.join(utils.abs_datapath(), 'blocked-hosts')
    url = QUrl(url)
    values.add(False, urlmatch.UrlPattern("*.foo.bar.baz"))
    with open(blocked_hosts, 'r', encoding='utf-8') as f:
        for line in f:
            values.add(False, urlmatch.UrlPattern(line))

    benchmark(lambda: values.get_for_url(url))
def test_add_url_benchmark(values, benchmark):
    blocked_hosts = os.path.join(utils.abs_datapath(), 'blocked-hosts')

    def _add_blocked():
        with open(blocked_hosts, 'r', encoding='utf-8') as f:
            for line in f:
                values.add(False, urlmatch.UrlPattern(line))

    benchmark(_add_blocked)
示例#3
0
def test_adblock_benchmark(config_stub, data_tmpdir, basedir, benchmark):
    blocked_hosts = os.path.join(utils.abs_datapath(), 'blocked-hosts')
    shutil.copy(blocked_hosts, str(data_tmpdir))

    url = QUrl('https://www.example.org/')
    blocker = adblock.HostBlocker()
    blocker.read_hosts()
    assert blocker._blocked_hosts

    benchmark(lambda: blocker.is_blocked(url))
示例#4
0
def test_adblock_benchmark(data_tmpdir, benchmark, host_blocker_factory):
    blocked_hosts = os.path.join(utils.abs_datapath(), 'blocked-hosts')
    shutil.copy(blocked_hosts, str(data_tmpdir))

    url = QUrl('https://www.example.org/')
    blocker = host_blocker_factory()
    blocker.read_hosts()
    assert blocker._blocked_hosts

    benchmark(lambda: blocker._is_blocked(url))