Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
* 0.9.3 - Addition of coverage support. Tests for traversal.py. pytest support. Test orchestration using pytest-order and pytest-dependency. Fixed TrieValueError export.
* 0.9.4 - Addition of tests for is_triekeytoke(), is_hashable(), get() methods and for TrieEntry(). Fixed bugs in TrieEntry __eq__ and __hash__ dunder methods. Rewrote __getitem__ and __contains__ dunder tests, added __delitem__ dunder tests. Excluded test_play.py and testspec.py from coverage measurements. Changed Nodes class to use __slots__ for attributes. Added tuplization of keys when creating TrieEntrys' to aid in immutability preservation.
* 0.9.5 - Benchmarking code, addition of py.typed for type support
* 0.9.6 - mypy types cleanup, addition of sphinxawesome-theme to \[dependency-groups.dev\]
121 changes: 59 additions & 62 deletions bench/bench_performance.py

Large diffs are not rendered by default.

26 changes: 17 additions & 9 deletions bench/benchmark_gentri.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
Benchmark for the Generalized Trie implementation.
This script runs a series of tests to measure the performance of the Generalized Trie
against a set of predefined test cases.

The Generalized Trie is a data structure that allows for efficient storage and retrieval
of keys that can be composed of various types of tokens, not just strings.


The benchmark includes tests for insertion, search, and deletion operations,
as well as tests for different key depths and symbol sets.

'''
# pylint: disable=wrong-import-position, too-many-instance-attributes
# pylint: disable=too-many-positional-arguments, too-many-arguments, too-many-locals
Expand Down Expand Up @@ -636,7 +644,7 @@ class BenchCase:
graph_y_starts_at_zero: bool = True
graph_x_labels_rotation: float = 0.0

def __post_init__(self):
def __post_init__(self) -> None:
self.results: list[BenchResults] = []

@property
Expand All @@ -650,7 +658,7 @@ def expanded_kwargs_variations(self) -> list[dict[str, Any]]:
values = [self.kwargs_variations[key] for key in keys]
return [dict(zip(keys, v)) for v in itertools.product(*values)]

def run(self):
def run(self) -> None:
"""Run the benchmark tests.

This method will execute the benchmark for each combination of
Expand Down Expand Up @@ -1042,23 +1050,23 @@ def default_runner(
description=f'[green] Benchmarking {group} (iteration {iteration_pass:<6d}; '
f'time {0.00:<3.2f}s)')
PROGRESS.start_task(TASKS[tasks_name])
total_elapsed: float = 0
total_elapsed: int = 0
iterations_list: list[BenchIteration] = []
while ((iteration_pass <= iterations_min or wall_time < min_stop_at)
and wall_time < max_stop_at):
iteration_pass += 1
iteration_result = BenchIteration()
iteration_result.elapsed = 0

if isinstance(setup, Callable):
if callable(setup):
setup()

# Timer for benchmarked code
timer_start: int = DEFAULT_TIMER()
action()
timer_end: int = DEFAULT_TIMER()

if isinstance(teardown, Callable):
if callable(teardown):
teardown()

if iteration_pass == 1:
Expand Down Expand Up @@ -1724,13 +1732,13 @@ def run_benchmarks(args: Namespace):
if case.results:
if args.json or args.json_data:
data_export.append(case.as_dict(args=args))

graph_file: Path
if args.graph:
if args.ops:
graph_file: Path = benchmark_run_dir.joinpath(f'benchmark_graph_ops_{case.group[:60]}.svg')
graph_file = benchmark_run_dir.joinpath(f'benchmark_graph_ops_{case.group[:60]}.svg')
case.plot_ops_results(graph_file)
if args.timing:
graph_file: Path = benchmark_run_dir.joinpath(f'benchmark_graph_timing_{case.group[:60]}.svg')
graph_file = benchmark_run_dir.joinpath(f'benchmark_graph_timing_{case.group[:60]}.svg')
case.plot_timing_results(graph_file)

if args.csv:
Expand Down Expand Up @@ -1782,7 +1790,7 @@ def run_benchmarks(args: Namespace):
PROGRESS.remove_task(task)


def main():
def main() -> None:
"""Main entry point for running benchmarks."""
parser = ArgumentParser(description='Run GeneralizedTrie benchmarks.')
parser.add_argument('--verbose', action='store_true', help='Enable verbose output')
Expand Down
2 changes: 1 addition & 1 deletion docs/html/.buildinfo.bak
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
config: e4d6d212882c2343c907aa4e56dbd288
config: 7ccba592787a2b5a3e11d3594a57a1d6
tags: 645f666f9bcd5a90fca523b33c5a78b7
2 changes: 1 addition & 1 deletion docs/html/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const DOCUMENTATION_OPTIONS = {
VERSION: '0.9.4',
VERSION: '0.9.6',
LANGUAGE: 'en',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
14 changes: 7 additions & 7 deletions docs/html/benchmarks.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<meta content="white" media="(prefers-color-scheme: light)" name="theme-color"/>
<meta content="black" media="(prefers-color-scheme: dark)" name="theme-color"/>
<meta content="width=device-width, initial-scale=1" name="viewport"/>
<title>Benchmarks | gen-tries 0.9.4 documentation</title>
<meta content="Benchmarks | gen-tries 0.9.4 documentation" property="og:title"/>
<meta content="Benchmarks | gen-tries 0.9.4 documentation" name="twitter:title"/>
<title>Benchmarks | gen-tries 0.9.6 documentation</title>
<meta content="Benchmarks | gen-tries 0.9.6 documentation" property="og:title"/>
<meta content="Benchmarks | gen-tries 0.9.6 documentation" name="twitter:title"/>
<link href="_static/pygments.css?v=c309799c" rel="stylesheet" type="text/css"/>
<link href="_static/theme.css?v=42baaae4" rel="stylesheet" type="text/css"/>
<link href="search.html" rel="search" title="Search"/>
Expand All @@ -34,7 +34,7 @@
Skip to content
</a><header class="sticky top-0 z-40 w-full border-b shadow-sm border-border supports-backdrop-blur:bg-background/60 bg-background/95 backdrop-blur"><div class="container flex items-center h-14">
<div class="hidden mr-4 md:flex">
<a class="flex items-center mr-6" href="index.html"><span class="hidden font-bold sm:inline-block text-clip whitespace-nowrap">gen-tries 0.9.4 documentation</span>
<a class="flex items-center mr-6" href="index.html"><span class="hidden font-bold sm:inline-block text-clip whitespace-nowrap">gen-tries 0.9.6 documentation</span>
</a></div><button @click="showSidebar = true" class="inline-flex items-center justify-center h-10 px-0 py-2 mr-2 text-base font-medium transition-colors rounded-md hover:text-accent-foreground hover:bg-transparent md:hidden" type="button">
<svg aria-hidden="true" fill="currentColor" height="24" viewbox="0 96 960 960" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M152.587 825.087q-19.152 0-32.326-13.174t-13.174-32.326q0-19.152 13.174-32.326t32.326-13.174h440q19.152 0 32.326 13.174t13.174 32.326q0 19.152-13.174 32.326t-32.326 13.174h-440Zm0-203.587q-19.152 0-32.326-13.174T107.087 576q0-19.152 13.174-32.326t32.326-13.174h320q19.152 0 32.326 13.174T518.087 576q0 19.152-13.174 32.326T472.587 621.5h-320Zm0-203.587q-19.152 0-32.326-13.174t-13.174-32.326q0-19.152 13.174-32.326t32.326-13.174h440q19.152 0 32.326 13.174t13.174 32.326q0 19.152-13.174 32.326t-32.326 13.174h-440ZM708.913 576l112.174 112.174q12.674 12.674 12.674 31.826t-12.674 31.826Q808.413 764.5 789.261 764.5t-31.826-12.674l-144-144Q600 594.391 600 576t13.435-31.826l144-144q12.674-12.674 31.826-12.674t31.826 12.674q12.674 12.674 12.674 31.826t-12.674 31.826L708.913 576Z"></path>
Expand Down Expand Up @@ -64,7 +64,7 @@
</div>
</header>
<div class="flex-1"><div class="container flex-1 items-start md:grid md:grid-cols-[220px_minmax(0,1fr)] md:gap-6 lg:grid-cols-[240px_minmax(0,1fr)] lg:gap-10"><aside :aria-hidden="!showSidebar" :class="{ 'translate-x-0': showSidebar }" class="fixed inset-y-0 left-0 md:top-14 z-50 md:z-30 bg-background md:bg-transparent transition-all duration-100 -translate-x-full md:translate-x-0 ml-0 p-6 md:p-0 md:-ml-2 md:h-[calc(100vh-3.5rem)] w-5/6 md:w-full shrink-0 overflow-y-auto border-r border-border md:sticky" id="left-sidebar">
<a class="!justify-start text-sm md:!hidden bg-background" href="index.html"><span class="font-bold text-clip whitespace-nowrap">gen-tries 0.9.4 documentation</span>
<a class="!justify-start text-sm md:!hidden bg-background" href="index.html"><span class="font-bold text-clip whitespace-nowrap">gen-tries 0.9.6 documentation</span>
</a>
<div class="relative overflow-hidden md:overflow-auto my-4 md:my-0 h-[calc(100vh-8rem)] md:h-auto">
<div class="overflow-y-auto h-full w-full relative pr-6"><nav class="table w-full min-w-full my-6 lg:my-8">
Expand Down Expand Up @@ -96,7 +96,7 @@
<div class="w-full min-w-0 mx-auto">
<nav aria-label="breadcrumbs" class="flex items-center mb-4 space-x-1 text-sm text-muted-foreground">
<a class="overflow-hidden text-ellipsis whitespace-nowrap hover:text-foreground" href="index.html">
<span class="hidden md:inline">gen-tries 0.9.4 documentation</span>
<span class="hidden md:inline">gen-tries 0.9.6 documentation</span>
<svg aria-label="Home" class="md:hidden" fill="currentColor" height="18" stroke="none" viewbox="0 96 960 960" width="18" xmlns="http://www.w3.org/2000/svg">
<path d="M240 856h120V616h240v240h120V496L480 316 240 496v360Zm-80 80V456l320-240 320 240v480H520V696h-80v240H160Zm320-350Z"></path>
</svg>
Expand Down Expand Up @@ -1102,7 +1102,7 @@ <h3>Creating a Trie Of English Words<a class="headerlink" href="#creating-a-trie
</div>
</footer>
</div>
<script src="_static/documentation_options.js?v=c5ca06ca"></script>
<script src="_static/documentation_options.js?v=564a08b9"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script defer="defer" src="_static/theme.js?v=073f68d9"></script>
Expand Down
16 changes: 9 additions & 7 deletions docs/html/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<meta name="theme-color" media="(prefers-color-scheme: light)" content="white" />
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="black" />

<title>Index | gen-tries 0.9.4 documentation</title>
<meta property="og:title" content="Index | gen-tries 0.9.4 documentation" />
<meta name="twitter:title" content="Index | gen-tries 0.9.4 documentation" />
<title>Index | gen-tries 0.9.6 documentation</title>
<meta property="og:title" content="Index | gen-tries 0.9.6 documentation" />
<meta name="twitter:title" content="Index | gen-tries 0.9.6 documentation" />
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=c309799c" />
<link rel="stylesheet" type="text/css" href="_static/theme.css?v=42baaae4" />
<link rel="search" title="Search" href="search.html" />
Expand All @@ -39,7 +39,7 @@
</a><header
class="sticky top-0 z-40 w-full border-b shadow-sm border-border supports-backdrop-blur:bg-background/60 bg-background/95 backdrop-blur"><div class="container flex items-center h-14">
<div class="hidden mr-4 md:flex">
<a href="index.html" class="flex items-center mr-6"><span class="hidden font-bold sm:inline-block text-clip whitespace-nowrap">gen-tries 0.9.4 documentation</span>
<a href="index.html" class="flex items-center mr-6"><span class="hidden font-bold sm:inline-block text-clip whitespace-nowrap">gen-tries 0.9.6 documentation</span>
</a></div><button
class="inline-flex items-center justify-center h-10 px-0 py-2 mr-2 text-base font-medium transition-colors rounded-md hover:text-accent-foreground hover:bg-transparent md:hidden"
type="button" @click="showSidebar = true">
Expand Down Expand Up @@ -94,7 +94,7 @@
class="fixed inset-y-0 left-0 md:top-14 z-50 md:z-30 bg-background md:bg-transparent transition-all duration-100 -translate-x-full md:translate-x-0 ml-0 p-6 md:p-0 md:-ml-2 md:h-[calc(100vh-3.5rem)] w-5/6 md:w-full shrink-0 overflow-y-auto border-r border-border md:sticky"
:aria-hidden="!showSidebar" :class="{ 'translate-x-0': showSidebar }">

<a href="index.html" class="!justify-start text-sm md:!hidden bg-background"><span class="font-bold text-clip whitespace-nowrap">gen-tries 0.9.4 documentation</span>
<a href="index.html" class="!justify-start text-sm md:!hidden bg-background"><span class="font-bold text-clip whitespace-nowrap">gen-tries 0.9.6 documentation</span>
</a>

<div class="relative overflow-hidden md:overflow-auto my-4 md:my-0 h-[calc(100vh-8rem)] md:h-auto">
Expand Down Expand Up @@ -133,7 +133,7 @@
class="flex items-center mb-4 space-x-1 text-sm text-muted-foreground">
<a class="overflow-hidden text-ellipsis whitespace-nowrap hover:text-foreground"
href="index.html">
<span class="hidden md:inline">gen-tries 0.9.4 documentation</span>
<span class="hidden md:inline">gen-tries 0.9.6 documentation</span>
<svg xmlns="http://www.w3.org/2000/svg"
height="18"
width="18"
Expand Down Expand Up @@ -183,6 +183,8 @@ <h2 id="C">C</h2>

<ul style="list-style-type:none">
<li><a href="gentrie.trie.html#gentrie.trie.base.TrieBase.clear">(gentrie.trie.base.TrieBase method)</a>
</li>
<li><a href="gentrie.trie.html#gentrie.trie.trie_mixins.TrieMixinsInterface.clear">(gentrie.trie.trie_mixins.TrieMixinsInterface method)</a>
</li>
</ul></li>
</ul></td>
Expand Down Expand Up @@ -747,7 +749,7 @@ <h2 id="V">V</h2>
</footer>
</div>

<script src="_static/documentation_options.js?v=c5ca06ca"></script>
<script src="_static/documentation_options.js?v=564a08b9"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script defer="defer" src="_static/theme.js?v=073f68d9"></script>
Expand Down
Loading