-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add simple benchmark * reorganize bench into separate folder * add benchmarking setup * remove --benchmark-autosave * black * tune benchmarks to have lower stddev * made the benchmark about 2-3x faster * litn * add another case to benchmark * Fix linting * Don't run the benchmark in pre-commit hook --------- Co-authored-by: Berend Klein Haneveld <[email protected]>
- Loading branch information
1 parent
c295c76
commit 95756af
Showing
9 changed files
with
178 additions
and
19 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
__pycache__ | ||
.vscode | ||
.coverage | ||
dist | ||
dist | ||
.benchmarks |
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,28 @@ | ||
from observ import reactive, watch | ||
|
||
|
||
def noop(): | ||
pass | ||
|
||
|
||
# @profile | ||
def main(): | ||
obj = reactive({}) | ||
|
||
watch(obj, callback=noop, deep=True, sync=True) | ||
|
||
obj["bar"] = "baz" | ||
obj["quux"] = "quuz" | ||
obj.update( | ||
{ | ||
"bar": "foo", | ||
"quazi": "var", | ||
} | ||
) | ||
del obj["bar"] | ||
_ = obj["quux"] | ||
obj.clear() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,84 @@ | ||
from functools import partial | ||
|
||
import pytest | ||
|
||
from observ import reactive, watch | ||
|
||
|
||
def noop(): | ||
pass | ||
|
||
|
||
N = 10000 | ||
|
||
|
||
def bench_dict(plain, add_watcher): | ||
for _ in range(N): | ||
obj = {} if plain else reactive({}) | ||
if add_watcher: | ||
watcher = watch(obj, callback=noop, deep=True, sync=True) # noqa: F841 | ||
obj["bar"] = "baz" | ||
obj["quux"] = "quuz" | ||
obj.update( | ||
{ | ||
"bar": "foo", | ||
"quazi": "var", | ||
} | ||
) | ||
del obj["bar"] | ||
_ = obj["quux"] # read something | ||
obj.clear() | ||
|
||
|
||
@pytest.mark.timeout(timeout=0) | ||
@pytest.mark.benchmark( | ||
group="dict_plain_vs_reactive", | ||
) | ||
@pytest.mark.parametrize("name", ["plain", "reactive", "reactive+watcher"]) | ||
def test_dict_plain_vs_reactive(benchmark, name): | ||
bench_fn = partial(bench_dict, name == "plain", name.endswith("+watcher")) | ||
benchmark(bench_fn) | ||
|
||
|
||
def bench_list(plain, add_watcher): | ||
for _ in range(N): | ||
obj = [] if plain else reactive([]) | ||
if add_watcher: | ||
watcher = watch(obj, callback=noop, deep=True, sync=True) # noqa: F841 | ||
obj.append("bar") | ||
obj.extend(["quux", "quuz"]) | ||
obj[1] = "foo" | ||
obj.pop(0) | ||
_ = obj[0] # read something | ||
obj.clear() | ||
|
||
|
||
@pytest.mark.timeout(timeout=0) | ||
@pytest.mark.benchmark( | ||
group="list_plain_vs_reactive", | ||
) | ||
@pytest.mark.parametrize("name", ["plain", "reactive", "reactive+watcher"]) | ||
def test_list_plain_vs_reactive(benchmark, name): | ||
bench_fn = partial(bench_list, name == "plain", name.endswith("+watcher")) | ||
benchmark(bench_fn) | ||
|
||
|
||
def bench_set(plain, add_watcher): | ||
for _ in range(N): | ||
obj = set() if plain else reactive(set()) | ||
if add_watcher: | ||
watcher = watch(obj, callback=noop, deep=True, sync=True) # noqa: F841 | ||
obj.add("bar") | ||
obj.update({"quux", "quuz"}) | ||
_ = list(iter(obj)) # read something | ||
obj.clear() | ||
|
||
|
||
@pytest.mark.timeout(timeout=0) | ||
@pytest.mark.benchmark( | ||
group="set_plain_vs_reactive", | ||
) | ||
@pytest.mark.parametrize("name", ["plain", "reactive", "reactive+watcher"]) | ||
def test_set_plain_vs_reactive(benchmark, name): | ||
bench_fn = partial(bench_set, name == "plain", name.endswith("+watcher")) | ||
benchmark(bench_fn) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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