aboutsummaryrefslogtreecommitdiffstats
path: root/src/remake/bench.rs
blob: fa9f35843c137fb8233fb1f80da60fc100df7eb7 (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
//! Benchmarks, as ignored tests (`cargo benchmarks`, `docs/development.md`).
//!
//! `replay`: carrying writes over into a new epoch's document, last writer wins
//! (`delta::replay_newest`): what a rejoin does with the writes made during it, and a
//! switch with those made after the remake's base. It finds the paths of every write
//! carried, and of every newer change in the new document, from its operations
//! (`store::changed_by`).

use std::time::Instant;

use super::delta::{Superseded, replay_newest};
use super::kind::Translator;
use crate::document::bench::{document, median, snapshot, writes};

/// `late` writes made to the old document after `keys` keys, carried into a new one
/// holding those keys (as a snapshot, at time 0) and `newer` writes of its own made
/// after them.
fn replay(keys: usize, late: usize, newer: usize) {
    let old_base = document(keys);
    let base = old_base.get_heads();
    let mut old = old_base.clone();
    writes(&mut old, 0, late, 1_000);
    let after = old.get_heads();

    let mut new = snapshot(&old_base);
    writes(&mut new, late, newer, 2_000);

    let took = median(5, || {
        let mut target = new.clone();
        let started = Instant::now();
        std::hint::black_box(replay_newest(
            &old,
            &base,
            &after,
            &mut target,
            &Translator::default(),
            Superseded::Drop,
        ));
        started.elapsed()
    });
    println!(
        "{:<60} {:>10.3} ms",
        format!("replay of {late} writes, {keys} keys, {newer} newer changes"),
        took.as_secs_f64() * 1e3
    );
}

#[test]
#[ignore = "a benchmark: cargo benchmarks"]
fn bench_replay() {
    println!(""); // put reports on new line
    replay(1_000, 100, 100);
    replay(100_000, 100, 100);
    replay(100_000, 1_000, 1_000);
}