File: benchmark_template.py

package info (click to toggle)
python-polsarpro 2026.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 17,024 kB
  • sloc: python: 3,830; xml: 293; sh: 91; javascript: 18; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 985 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# this script may be used to measure running time of any function
# since bench.timeit is not accurate for dask based processing

from pathlib import Path
from polsarpro.io import open_netcdf_beam
from polsarpro.decompositions import h_a_alpha
import time

# change to your data paths
# original dataset
input_alos_slc = Path("/data/psp/test_files/SAN_FRANCISCO_ALOS1_slc.nc")
input_alos_slc_re = Path("/data/psp/test_files/SAN_FRANCISCO_ALOS1_slc_rechunked.nc")

# input files from C
input_test_dir = Path("/data/psp/test_files/input/h_a_alpha_decomposition/")

# output files from C
output_test_dir = Path("/data/psp/res/h_a_alpha_c")

n_runs = 3
# %%
test_path = "/data/psp/test_files/test.zarr"
slc = open_netcdf_beam(input_alos_slc)
for _ in range(n_runs):
    start_time = time.perf_counter()
    res_slc = h_a_alpha(slc, boxcar_size=[7, 7]).compute()
    end_time = time.perf_counter()
    total_time = end_time - start_time
    print(f"Function took {total_time:.4f} seconds")