def make_score(note_count):
with abjad.Timer() as timer:
notes = [abjad.Note("c'8") for _ in range(note_count)]
staff = abjad.Staff(notes)
score = abjad.Score([staff])
time = int(timer.elapsed_time)
print(f"made {note_count} notes in {time} seconds ...")
return score
def attach_indicators(score, indicator_classes):
leaves = abjad.select(score).leaves()
total = 0
with abjad.Timer() as timer:
for leaf in leaves:
for indicator_class in indicator_classes:
indicator = indicator_class()
abjad.attach(indicator, leaf)
total += 1
time = int(timer.elapsed_time)
print(f"attached {total} contexted indicators in {time} seconds ...")
def detach_indicators(argument, indicator_classes):
leaves = abjad.select(argument).leaves()
total = 0
with abjad.Timer() as timer:
for leaf in leaves:
for indicator_class in indicator_classes:
result = abjad.detach(indicator_class, leaf)
total += len(result or [])
time = int(timer.elapsed_time)
print(f"detached {total} contexted indicators in {time} seconds ...")
class Foo:
context = "Staff"
class Bar:
context = "Staff"
class Baz:
context = "Staff"
class Qux:
context = "Staff"
class Qul:
context = "Staff"
Observation: runtime increases linearly with the number of contexted indicators:
Test functions:
Observation: runtime increases linearly with the number of contexted indicators:
Observation: runtime increases exponentially with the number of notes:
Solution: remove calls to Python's
inspect
module fromabjad.Wrapper.__eq__()
.Current definition in Abjad 3.4:
Redefinition:
Redefinition reduces runtime to zero:
abjad.format.compare_objects()
is used only in definitions of__eq__()
.Conclusion: remove
abjad.format.compare_objects()
.