2021-08-24 16:43:46 +00:00
|
|
|
#![allow(non_snake_case, non_upper_case_globals)]
|
2021-08-23 17:15:57 +00:00
|
|
|
//! This benchmark tests just the overhead of Dioxus itself.
|
|
|
|
//!
|
|
|
|
//! For the JS Framework Benchmark, both the framework and the browser is benchmarked together. Dioxus prepares changes
|
|
|
|
//! to be made, but the change application phase will be just as performant as the vanilla wasm_bindgen code. In essence,
|
|
|
|
//! we are measuring the overhead of Dioxus, not the performance of the "apply" phase.
|
|
|
|
//!
|
|
|
|
//! On my MBP 2019:
|
|
|
|
//! - Dioxus takes 3ms to create 1_000 rows
|
|
|
|
//! - Dioxus takes 30ms to create 10_000 rows
|
|
|
|
//!
|
2021-08-24 16:43:46 +00:00
|
|
|
//! As pure "overhead", these are amazing good numbers, mostly slowed down by hitting the global allocator.
|
2021-08-23 17:15:57 +00:00
|
|
|
//! These numbers don't represent Dioxus with the heuristic engine installed, so I assume it'll be even faster.
|
|
|
|
|
2021-08-24 16:43:46 +00:00
|
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
2021-08-23 17:15:57 +00:00
|
|
|
use dioxus_core as dioxus;
|
|
|
|
use dioxus_core::prelude::*;
|
2021-09-25 01:46:23 +00:00
|
|
|
use dioxus_core_macro::*;
|
2021-08-23 17:15:57 +00:00
|
|
|
use dioxus_html as dioxus_elements;
|
|
|
|
use rand::prelude::*;
|
|
|
|
|
|
|
|
criterion_group!(mbenches, create_rows);
|
|
|
|
criterion_main!(mbenches);
|
|
|
|
|
|
|
|
fn create_rows(c: &mut Criterion) {
|
2021-12-15 20:56:53 +00:00
|
|
|
static App: Component<()> = |cx| {
|
2021-08-23 17:15:57 +00:00
|
|
|
let mut rng = SmallRng::from_entropy();
|
2021-10-16 21:04:28 +00:00
|
|
|
let rows = (0..10_000_usize).map(|f| {
|
2021-08-23 17:15:57 +00:00
|
|
|
let label = Label::new(&mut rng);
|
2021-11-19 05:49:04 +00:00
|
|
|
rsx!(Row {
|
|
|
|
row_id: f,
|
|
|
|
label: label
|
|
|
|
})
|
2021-08-23 17:15:57 +00:00
|
|
|
});
|
2021-11-19 05:49:04 +00:00
|
|
|
rsx!(cx, table {
|
|
|
|
tbody {
|
|
|
|
{rows}
|
2021-08-23 17:15:57 +00:00
|
|
|
}
|
2021-10-30 01:43:21 +00:00
|
|
|
})
|
2021-08-23 17:15:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
c.bench_function("create rows", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let mut dom = VirtualDom::new(App);
|
2021-08-24 19:12:20 +00:00
|
|
|
let g = dom.rebuild();
|
2021-08-23 17:15:57 +00:00
|
|
|
assert!(g.edits.len() > 1);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Props)]
|
|
|
|
struct RowProps {
|
|
|
|
row_id: usize,
|
|
|
|
label: Label,
|
|
|
|
}
|
2021-12-15 20:56:53 +00:00
|
|
|
fn Row(cx: Scope<RowProps>) -> Element {
|
|
|
|
let [adj, col, noun] = cx.props.label.0;
|
2021-10-30 01:43:21 +00:00
|
|
|
cx.render(rsx! {
|
2021-08-23 17:15:57 +00:00
|
|
|
tr {
|
2021-12-15 20:56:53 +00:00
|
|
|
td { class:"col-md-1", "{cx.props.row_id}" }
|
2021-08-23 17:15:57 +00:00
|
|
|
td { class:"col-md-1", onclick: move |_| { /* run onselect */ }
|
2021-08-24 16:43:46 +00:00
|
|
|
a { class: "lbl", "{adj}" "{col}" "{noun}" }
|
2021-08-23 17:15:57 +00:00
|
|
|
}
|
|
|
|
td { class: "col-md-1"
|
|
|
|
a { class: "remove", onclick: move |_| {/* remove */}
|
|
|
|
span { class: "glyphicon glyphicon-remove remove" aria_hidden: "true" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
td { class: "col-md-6" }
|
|
|
|
}
|
2021-10-30 01:43:21 +00:00
|
|
|
})
|
2021-08-23 17:15:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
struct Label([&'static str; 3]);
|
|
|
|
|
|
|
|
impl Label {
|
|
|
|
fn new(rng: &mut SmallRng) -> Self {
|
|
|
|
Label([
|
|
|
|
ADJECTIVES.choose(rng).unwrap(),
|
|
|
|
COLOURS.choose(rng).unwrap(),
|
|
|
|
NOUNS.choose(rng).unwrap(),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static ADJECTIVES: &[&str] = &[
|
|
|
|
"pretty",
|
|
|
|
"large",
|
|
|
|
"big",
|
|
|
|
"small",
|
|
|
|
"tall",
|
|
|
|
"short",
|
|
|
|
"long",
|
|
|
|
"handsome",
|
|
|
|
"plain",
|
|
|
|
"quaint",
|
|
|
|
"clean",
|
|
|
|
"elegant",
|
|
|
|
"easy",
|
|
|
|
"angry",
|
|
|
|
"crazy",
|
|
|
|
"helpful",
|
|
|
|
"mushy",
|
|
|
|
"odd",
|
|
|
|
"unsightly",
|
|
|
|
"adorable",
|
|
|
|
"important",
|
|
|
|
"inexpensive",
|
|
|
|
"cheap",
|
|
|
|
"expensive",
|
|
|
|
"fancy",
|
|
|
|
];
|
|
|
|
|
|
|
|
static COLOURS: &[&str] = &[
|
|
|
|
"red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black",
|
|
|
|
"orange",
|
|
|
|
];
|
|
|
|
|
|
|
|
static NOUNS: &[&str] = &[
|
|
|
|
"table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger",
|
|
|
|
"pizza", "mouse", "keyboard",
|
|
|
|
];
|