Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add the 'btree' benchmark. #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
Loading
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove unused methods in BTree classes.
  • Loading branch information
nascheme committed Jan 30, 2025
commit bc21dbcce892cf1323d9adc31b1f013de7572907
59 changes: 4 additions & 55 deletions 59 pyperformance/data-files/benchmarks/bm_btree/run_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
object graph.
"""

import collections.abc
import gc
import random
import sys
Expand Down Expand Up @@ -127,15 +126,6 @@ def get_count(self):
result += node.get_count()
return result

def get_node_count(self):
"""() -> int
How many nodes are here, including descendants?
"""
result = 1
for node in self.nodes or []:
result += node.get_node_count()
return result

def get_level(self):
"""() -> int
How many levels of nodes are there between this node
Expand Down Expand Up @@ -236,23 +226,20 @@ def is_big(node):
self.nodes = self.nodes[0].nodes


class BTree(collections.abc.MutableMapping):
class BTree:
"""
Instance attributes:
root: BNode
"""

__slots__ = ['root']

def __init__(self, node_constructor=BNode):
assert issubclass(node_constructor, BNode)
self.root = node_constructor()
def __init__(self):
self.root = BNode()

def __nonzero__(self):
def __bool__(self):
return bool(self.root.items)

__bool__ = __nonzero__

def iteritems(self):
for item in self.root:
yield item
Expand All @@ -261,39 +248,16 @@ def iterkeys(self):
for item in self.root:
yield item[0]

def itervalues(self):
for item in self.root:
yield item[1]

def items(self):
return list(self.iteritems())

def keys(self):
return list(self.iterkeys())

def values(self):
return list(self.itervalues())

def __iter__(self):
for key in self.iterkeys():
yield key

def __contains__(self, key):
return self.root.search(key) is not None

def has_key(self, key):
return self.root.search(key) is not None

def __setitem__(self, key, value):
self.add(key, value)

def setdefault(self, key, value):
item = self.root.search(key)
if item is None:
self.add(key, value)
return value
return item[1]

def __getitem__(self, key):
item = self.root.search(key)
if item is None:
Expand All @@ -303,9 +267,6 @@ def __getitem__(self, key):
def __delitem__(self, key):
self.root.delete(key)

def clear(self):
self.root = self.root.__class__()

def get(self, key, default=None):
"""(key:anything, default:anything=None) -> anything"""
try:
Expand All @@ -330,18 +291,6 @@ def __len__(self):
Compute and return the total number of items."""
return self.root.get_count()

def get_depth(self):
"""() -> int
How many levels of nodes are used for this BTree?
"""
return self.root.get_level() + 1

def get_node_count(self):
"""() -> int
How many nodes are used for this BTree?
"""
return self.root.get_node_count()


class Record:
def __init__(self, a, b, c, d, e, f):
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.