3. Benchmarking and Profiling

3. Benchmarking and Profiling#

Introduction#

The benchmarking is essential to the progress and success of the project. Also, benchmarking code is a essential part of software development and it’s a software best practice. It can’t keep implementing new features without ensuring that what have been done. With benchmarking, we can confirm that our software does what it’s supposed to, and that it can handle most of the cases.

Memory Profiler#

Echoshader uses Time-based memory usage in Memory Profiler to execute benchmarking. This is a python module for monitoring memory consumption of a process as well as line-by-line analysis of memory consumption for python programs. It is a pure python module which depends on the psutil module.

Testing code, results and exporting HTMLs have been posted on Google Drive.

Admin Panel#

Also, we can take use of Admin Panel in Panel library.

The /admin panel provides an overview of the current application and provides tools for debugging and profiling. It can be enabled by passing the --admin argument to the panel serve command.

For example, we build a new testing file called ‘your_file_name.py’ or ‘your_file_name.ipynb’ below:

import xarray as xr
from pathlib import Path

from echoshader import echogram

MVBS_ds = xr.open_mfdataset(
    str('test_admin.nc'),
    data_vars='minimal', coords='minimal',
    combine='by_coords'
)

pn = echogram.panel

echogram = echogram.Echogram(MVBS_ds)

pn.Row(echogram.widgets, echogram.view_gram).servable()

Don’t forget to use .servable() to specify which component you want to display in the browser.

Then we input below command in cmd Prompt or Anaconda Prompt to start up the server:

panel serve --admin --profiler=snakeviz your_file_name.py

Users should use the commandline --admin and --profiler options. Don’t forget to specify the profiler.

Once enabled the server, input below urls to open procedure page and admin page:

http://localhost:your_port_number/your_file_name
http://localhost:your_port_number/admin

The overview page provides some details about currently active sessions, running versions and resource usage (if psutil is installed).

image-20220906212522202

The launch profiler profiles the execution time of the initialization of a particular application. It can be enabled by setting a profiler using the commandline --profiler option. Available profilers include:

  • pyinstrument: A statistical profiler with nice visual output

  • snakeviz: SnakeViz is a browser based graphical viewer for the output of Python’s cProfile module and an alternative to using the standard library pstats module.

Once enabled the launch profiler will profile each application separately and provide the profiler output generated by the selected profiling engine.

image-20220906212522202