Skip to content

Speed up ProcessWithContext.process_*()#104

Merged
hagenw merged 3 commits intomainfrom
speed-up-process-with-context
Mar 13, 2023
Merged

Speed up ProcessWithContext.process_*()#104
hagenw merged 3 commits intomainfrom
speed-up-process-with-context

Conversation

@frankenjoe
Copy link
Copy Markdown
Collaborator

Relates to #100

Speeds up PredictWithContext.process_*() by avoiding calls to pd.concat() on a lot of small pd.Series objects. Instead, we now concatenate lists and create the final pd.Series from those.

Benchmark

import time
import audb
import audinterface


db = audb.load(
    'emodb',
    version='1.3.0',
    format='wav',
    sampling_rate=16000,
    mixdown=True,
)

def process_func(x, sr, starts, ends):
    y = []
    for start, end in zip(starts, ends):
        y.append(x[:, start:end].mean())
    return y

process = audinterface.ProcessWithContext(process_func=process_func)

t = time.time()
process.process_index(db.files)
print(time.time() - t)
  • main branch: ~4.0 s
  • this branch: ~0.6 s

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 10, 2023

Codecov Report

Merging #104 (f0a77ee) into main (7ad15b7) will not change coverage.
The diff coverage is 100.0%.

Impacted Files Coverage Δ
audinterface/core/process_with_context.py 100.0% <100.0%> (ø)

... and 2 files with indirect coverage changes

@hagenw
Copy link
Copy Markdown
Member

hagenw commented Mar 13, 2023

As the main branch now incorporates #102 and #103 I re-did the benchmark and I get:

  • main branch: ~1.9 s
  • this branch: ~0.4 s

Comment thread audinterface/core/process_with_context.py
Comment thread audinterface/core/process_with_context.py
@hagenw hagenw merged commit c74dfff into main Mar 13, 2023
@hagenw hagenw deleted the speed-up-process-with-context branch March 13, 2023 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants