File: benchmark_vincenty.py

package info (click to toggle)
pymap3d 3.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 540 kB
  • sloc: python: 3,742; ruby: 105; makefile: 4
file content (66 lines) | stat: -rwxr-xr-x 1,393 bytes parent folder | download | duplicates (2)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
"""
vreckon and vdist are iterative algorithms.
How much does PyPy help over Cpython?

Hmm, PyPy is slower than Cpython..

$ pypy3 tests/benchmark_vincenty.py 10000
2.1160879135131836
0.06056046485900879

$ python tests/benchmark_vincenty.py 10000
0.3325080871582031
0.02107095718383789
"""

import argparse
import shutil
import subprocess
import time
from pathlib import Path

import numpy as np
from pymap3d.vincenty import vdist, vreckon

R = Path(__file__).parent

MATLAB = shutil.which("matlab")

ll0 = (42.0, 82.0)


def bench_vreckon(N: int) -> float:
    sr = np.random.random(N)
    az = np.random.random(N)

    tic = time.monotonic()
    _, _ = vreckon(ll0[0], ll0[1], sr, az)

    return time.monotonic() - tic


def bench_vdist(N: int) -> float:
    lat = np.random.random(N)
    lon = np.random.random(N)

    tic = time.monotonic()
    _, _ = vdist(ll0[0], ll0[1], lat, lon)

    return time.monotonic() - tic


if __name__ == "__main__":
    p = argparse.ArgumentParser()
    p.add_argument("N", help="number of iterations", type=int)
    args = p.parse_args()
    N = args.N

    print(f"vreckon: {bench_vreckon(N):.3f}")
    print(f"vdist: {bench_vdist(N):.3f}")

    if MATLAB:
        print(f"matlab path {R}")
        subprocess.check_call(
            f'matlab -batch "helper_vdist({ll0[0]}, {ll0[1]}, {N})"', text=True, timeout=90, cwd=R
        )