summaryrefslogtreecommitdiffstats
path: root/benches/parsing.rs
blob: 0bfe44c0d32504b1fc169655d8030c84b57535d8 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use so::stackexchange::scraper::{DuckDuckGo, Google, Scraper};
use std::collections::HashMap;
use std::time::Duration;

fn bench_parsers(c: &mut Criterion) {
    let limit: u16 = 10;
    let mut sites = HashMap::new();
    sites.insert(
        String::from("stackoverflow"),
        String::from("stackoverflow.com"),
    );
    sites.insert(String::from("askubuntu"), String::from("askubuntu.com"));

    let mut group = c.benchmark_group("Scraping html");

    group.sample_size(80);
    group.measurement_time(Duration::from_secs(10));
    group.throughput(Throughput::Elements(limit as u64));

    group.bench_with_input(
        BenchmarkId::new("Google.parse", "exit-vim"),
        include_str!("../test/google/exit-vim.html"),
        |b, html| b.iter(|| Google.parse(html, &sites, limit)),
    );

    group.bench_with_input(
        BenchmarkId::new("DuckDuckGo.parse", "exit-vim"),
        include_str!("../test/duckduckgo/exit-vim.html"),
        |b, html| b.iter(|| DuckDuckGo.parse(html, &sites, limit)),
    );

    let mut sites = HashMap::new();
    sites.insert(
        String::from("stackoverflow"),
        String::from("stackoverflow.com"),
    );

    group.bench_with_input(
        BenchmarkId::new("Google.parse", "/q/"),
        include_str!("../test/google/parsing-q.html"),
        |b, html| b.iter(|| Google.parse(html, &sites, limit)),
    );

    let mut sites = HashMap::new();
    sites.insert(String::from("meta"), String::from("meta.stackexchange.com"));

    group.bench_with_input(
        BenchmarkId::new("DuckDuckGo.parse", "tagged"),
        include_str!("../test/duckduckgo/tagged.html"),
        |b, html| b.iter(|| DuckDuckGo.parse(html, &sites, limit)),
    );

    group.finish();
}

criterion_group!(benches, bench_parsers);
criterion_main!(benches);