Remove benchmarks for now as it does not work at all. (#2495)

This commit is contained in:
Kaede Hoshikawa 2022-03-07 22:28:58 +09:00 committed by GitHub
parent dce04f1a9b
commit f39afdc5e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 0 additions and 220 deletions

View File

@ -5,7 +5,6 @@
# * lint
# * lint-release
# * tests
# * benchmarks
#
# Run `cargo make --list-all-steps` for more details.
#
@ -40,12 +39,6 @@ dependencies = ["tests-setup"]
env = { CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = ["**/examples/*", "**/packages/changelog"] }
run_task = { name = ["test-flow", "doc-test-flow", "ssr-test", "website-test"], fork = true }
[tasks.benchmarks]
category = "Testing"
description = "Run benchmarks"
env = { CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = ["**/examples/*"] }
run_task = { name = "bench-flow", fork = true }
[tasks.lint-flow]
private = true
workspace = true
@ -98,16 +91,6 @@ args = ["test", "--doc"]
command = "cargo"
args = ["test", "-p", "website-test"]
[tasks.bench-flow]
private = true
workspace = true
dependencies = ["bench"]
[tasks.bench]
private = true
command = "cargo"
args = ["bench"]
[tasks.generate-change-log]
category = "Maintainer processes"
toolchain = "stable"

View File

@ -70,7 +70,6 @@ wasm-bindgen-futures = "0.4"
tokio = { version = "1.15.0", features = ["rt"], optional = true }
[dev-dependencies]
easybench-wasm = "0.2"
wasm-bindgen-test = "0.3"
gloo = { version = "0.6", features = ["futures"] }
wasm-bindgen-futures = "0.4"
@ -80,7 +79,6 @@ trybuild = "1"
[features]
doc_test = []
wasm_test = []
wasm_bench = []
ssr = ["futures", "html-escape"]
default = []

View File

@ -28,20 +28,6 @@ args = [
"doc_test,wasm_test",
]
[tasks.bench]
extend = "core::wasm-pack-base"
command = "wasm-pack"
args = [
"test",
"--release",
"--firefox",
"--headless",
"--",
"--features",
"wasm_bench",
"bench",
]
[tasks.ssr-test]
command = "cargo"
args = ["test", "ssr_tests", "--features", "ssr"]

View File

@ -270,190 +270,3 @@ impl Default for Attributes {
Self::Static(&[])
}
}
#[cfg(all(test, feature = "wasm_bench"))]
mod benchmarks {
use super::*;
use wasm_bindgen_test::{wasm_bindgen_test, wasm_bindgen_test_configure};
wasm_bindgen_test_configure!(run_in_browser);
macro_rules! run {
($name:ident => {
$( $old:expr => $new:expr )+
}) => {
// NB: these benchmarks only compare diffing. They do not take into account aspects like
// allocation impact, which is lower for both `Static` and `Dynamic`.
let results = vec![
$(
{
let mut old = $old.clone();
let new = $new.clone();
let el = gloo_utils::document().create_element("div").unwrap();
old.apply(&el);
(
format!("{} -> {}", attr_variant(&old), attr_variant(&new)),
easybench_wasm::bench_env_limit(
2.0,
(NodeCloner(el), new, old),
|(el, mut new, old)| new.apply_diff(&el.0, old),
),
)
},
)+
];
let max_name_len = results.iter().map(|(name, _)| name.len()).max().unwrap_or_default();
wasm_bindgen_test::console_log!(
"{}:{}",
stringify!($name),
results.into_iter().fold(String::new(), |mut acc, (name, res)| {
use std::fmt::Write;
write!(&mut acc, "\n\t\t{:<width$}: ", name, width=max_name_len).unwrap();
if res.ns_per_iter.is_nan() {
acc += "benchmark too slow to produce meaningful results";
} else {
write!(
&mut acc,
"{:>7.4} ns (R²={:.3}, {:>7} iterations in {:>3} samples)",
res.ns_per_iter,
res.goodness_of_fit,
res.iterations,
res.samples,
)
.unwrap();
}
acc
})
);
};
}
#[wasm_bindgen_test]
fn bench_diff_empty() {
let static_ = Attributes::Static(&[]);
let dynamic = Attributes::Dynamic {
keys: &[],
values: Box::new([]),
};
let map = Attributes::IndexMap(Default::default());
run! {
empty => {
static_ => static_
dynamic => dynamic
map => map
static_ => dynamic
static_ => map
dynamic => map
}
}
}
#[wasm_bindgen_test]
fn bench_diff_equal() {
let static_ = Attributes::Static(sample_attrs());
let dynamic = make_dynamic(sample_values());
let map = make_indexed_map(sample_values());
run! {
equal => {
static_ => static_
dynamic => dynamic
map => map
static_ => dynamic
static_ => map
dynamic => map
}
}
}
#[wasm_bindgen_test]
fn bench_diff_change_first() {
let old = sample_values();
let mut new = old.clone();
new[0] = AttrValue::Static("changed");
let dynamic = (make_dynamic(old.clone()), make_dynamic(new.clone()));
let map = (make_indexed_map(old), make_indexed_map(new));
run! {
changed_first => {
dynamic.0 => dynamic.1
map.0 => map.1
dynamic.0 => map.1
}
}
}
fn make_dynamic(values: Vec<AttrValue>) -> Attributes {
Attributes::Dynamic {
keys: sample_keys(),
values: values.into_iter().map(Some).collect(),
}
}
fn make_indexed_map(values: Vec<AttrValue>) -> Attributes {
Attributes::IndexMap(
sample_keys()
.iter()
.copied()
.zip(values.into_iter())
.collect(),
)
}
fn sample_keys() -> &'static [&'static str] {
&[
"oh", "boy", "pipes", "are", "from", "to", "and", "the", "side",
]
}
fn sample_values() -> Vec<AttrValue> {
[
"danny", "the", "the", "calling", "glen", "glen", "down", "mountain", "",
]
.iter()
.map(|v| AttrValue::Static(*v))
.collect()
}
fn sample_attrs() -> &'static [[&'static str; 2]] {
&[
["oh", "danny"],
["boy", "the"],
["pipes", "the"],
["are", "calling"],
["from", "glen"],
["to", "glen"],
["and", "down"],
["the", "mountain"],
["side", ""],
]
}
fn attr_variant(attrs: &Attributes) -> &'static str {
use Attributes::*;
match attrs {
Static(_) => "static",
Dynamic { .. } => "dynamic",
IndexMap(_) => "indexed_map",
}
}
/// Clones the node on [Clone] call
struct NodeCloner(Element);
impl Clone for NodeCloner {
fn clone(&self) -> Self {
use wasm_bindgen::JsCast;
Self(self.0.clone_node().unwrap().dyn_into().unwrap())
}
}
}