File: benchmark.py

package info (click to toggle)
jplephem 2.18%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 312 kB
  • sloc: python: 2,160; sh: 51; awk: 18; makefile: 4
file content (42 lines) | stat: -rwxr-xr-x 906 bytes parent folder | download
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
#!/usr/bin/env python

import numpy as np
import de421
from time import time
from jplephem import Ephemeris
from jplephem.spk import SPK

def main():
    for size in 10, 1000, 100000:
        jd = np.linspace(2414992.5, 2471184.50, size)
        kernel = SPK.open('de421.bsp')
        ephem = Ephemeris(de421)
        mars = kernel[0,4]

        print(size)
        print('-- old code (2 successive runs):')

        t0 = time()
        ephem.position('mars', jd)
        print(time() - t0)

        t0 = time()
        ephem.position('mars', jd)
        print(time() - t0)

        print('-- new SPK-powered code (2 successive runs):')

        t0 = time()
        mars.compute(jd)
        print(time() - t0)

        t0 = time()
        mars.compute(jd)
        print(time() - t0)

        print()

if __name__ == '__main__':
    main()
    print(' Warmed up, running again '.center(72, '-'))
    main()