-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: Add a class-selector-matching benchmark
- Loading branch information
1 parent
4d512e3
commit a1ce9fc
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-FileCopyrightText: 2025 Robin Lindén <[email protected]> | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
|
||
#include "style/style.h" | ||
|
||
#include "style/styled_node.h" | ||
|
||
#include "dom/dom.h" | ||
#include "etest/etest2.h" | ||
|
||
#include <nanobench.h> | ||
|
||
int main() { | ||
etest::Suite s; | ||
|
||
s.add_test("is_match: class", [](etest::IActions const &) { | ||
ankerl::nanobench::Bench bench; | ||
bench.title("is_match: class"); | ||
|
||
dom::Node few_classes_dom = dom::Element{"div", {{"class", "first second"}}}; | ||
auto few_classes = style::StyledNode{.node = few_classes_dom}; | ||
bench.run("match, few classes", [&] { | ||
style::is_match(few_classes, ".first.second"); // | ||
}); | ||
|
||
bench.run("no match, few classes", [&] { | ||
style::is_match(few_classes, ".first.second.third.fourth"); // | ||
}); | ||
|
||
dom::Node many_classes_dom = dom::Element{ | ||
"div", | ||
{{"class", "one two three four five six seven eight nine ten"}}, | ||
}; | ||
auto many_classes = style::StyledNode{.node = many_classes_dom}; | ||
bench.run("match, many classes", [&] { | ||
style::is_match(many_classes, ".eight.two.seven.ten"); // | ||
}); | ||
|
||
bench.run("no match, many classes", [&] { | ||
style::is_match(many_classes, ".eight.two.seve.ten"); // | ||
}); | ||
}); | ||
|
||
return s.run(); | ||
} |