Created
April 15, 2022 14:39
-
-
Save h-mayorquin/34bb26eeca38a33dbf27030c98e0a043 to your computer and use it in GitHub Desktop.
Test performance for spikeglx
This file contains hidden or 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
from datetime import datetime | |
from pathlib import Path | |
from nwb_conversion_tools import NWBConverter | |
output_path = Path("/home/heberto/") | |
def run_conversion_function(parameters_dic): | |
nwbfile_path = output_path / f"{str(parameters_dic['case_name'])}.nwb" | |
class TestConverter(NWBConverter): | |
data_interface_classes = dict(Interface=parameters_dic["data_interface"]) | |
stub_test = False | |
conversion_options = dict() | |
conversion_options.update(Interface=dict(stub_test=stub_test)) | |
converter = TestConverter(source_data=dict(Interface=parameters_dic["interface_kwargs"])) | |
metadata = converter.get_metadata() | |
converter.run_conversion( | |
nwbfile_path=nwbfile_path, conversion_options=conversion_options, overwrite=True, metadata=metadata | |
) | |
from nwb_conversion_tools import SpikeGLXRecordingInterface, SpikeGLXLFPInterface | |
DATA_PATH = Path("/home/heberto/ephy_testing_data/") | |
signal = "ap" | |
file_path = DATA_PATH / "spikeglx" / "Noise4Sam_g0" / "Noise4Sam_g0_imec0" / f"Noise4Sam_g0_t0.imec0.{signal}.bin" | |
spikeextractors_backend = True | |
case_name = f"{signal=},{spikeextractors_backend=}" | |
parameters_dict = dict( | |
data_interface=SpikeGLXRecordingInterface, # Datainterface to test | |
interface_kwargs=dict(file_path=str(file_path), | |
spikeextractors_backend=spikeextractors_backend, | |
), | |
case_name=case_name, | |
) | |
import cProfile, pstats | |
profiler = cProfile.Profile() | |
profiler.enable() | |
run_conversion_function(parameters_dict) | |
profiler.disable() | |
stats = pstats.Stats(profiler) | |
profiling_file_path = output_path / f"profiling_{case_name}.prof" | |
stats.dump_stats(str(profiling_file_path)) | |
# Print the stats report | |
with open(profiling_file_path.with_suffix(".txt"), "w") as f: | |
ps = pstats.Stats(str(profiling_file_path), stream=f) | |
ps.strip_dirs() | |
ps.sort_stats('cumtime') | |
ps.print_stats() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment