TKS Ephemeris · developer · performance

Performance Whitepaper & Swiss-Ephemeris Comparison

A reproducible benchmark of the TKS Ephemeris (JPL DE440) against the official Swiss Ephemeris C library, and an end-to-end profile of the Jyotiṣa page. Every figure below is reproducible from §5; measurements are best-of-three full runs on the machine in §1.

Headline. TKS's own compact kernel — TKS-EPH-1, 1.9 MB — runs the 11-body geocentric apparent-longitude workload (10,000 epochs, 110,000 positions) in 0.127 s: 1.31× faster than the full DE440 kernel (0.169 s, 114 MB) and 1.75× faster than Swiss Ephemeris in file mode (0.222 s), at a maximum residual of 0.092″; on all 14 cores it drops to 0.013 s (9.6×). The whole Jyotiṣa chart (25 computations) renders in a median 12.5 ms.

1 · Environment

CPUApple M3 Max — 14 cores (10 performance + 4 efficiency)
Memory36 GB unified · Model Mac15,10
OSmacOS 26.6.2 (Darwin 25.6.0, arm64 / T6031)
Toolchainrustc 1.98.0 · --release
TKS EphemerisTKS-EPH-1 (100-yr, tks-eph-1_1950-2050.tkseph) and TKS-EPH-2 (1550–2650, tks-eph-2_1550-2650.tkseph) · Chebyshev · true Chitrāpakṣa
source ephemeris data: JPL DE440 · re-measured 2026-10-08
Swiss Ephemerispyswisseph 2.10.03 · real .se1 files (1800–2400), file mode (verified via returned flags, not the Moshier fallback)

2 · Ephemeris throughput — 10,000 × 11 = 110,000 positions

Bodies: Sun · Moon · Mercury · Venus · Mars · Jupiter · Saturn · Uranus · Neptune · Pluto · True-Node. Geocentric apparent tropical longitude, 1-day spacing. Single thread unless stated; best of 3; re-measured on 2026-10-08 on the environment in §1 (same machine, same run for Swiss).

EngineTotal (best-of-3)per 11-body setper positionvs Swiss
TKS-EPH-2 (1550–2650, 28.5 MB) + per-epoch reduction0.038 s0.0038 ms0.347 µs3.9× faster
TKS-EPH-1 (100-yr, 1.9 MB)0.038 s0.0038 ms0.343 µs3.9× faster
TKS-EPH-2 — all cores (Rayon, 14 threads)0.004 s0.0004 ms0.033 µs41× vs Swiss single-thread
TKS Ephemeris — full DE440 kernel (120 MB) + per-epoch reduction0.075 s0.0068 ms0.684 µs2.0× faster
TKS production pipeline (server path: shared Earth/Sun, DE440)0.100 s0.0091 ms0.907 µs1.5× faster
Swiss Ephemeris 2.10.03 — C library, files, positions only0.148 s0.0136 ms1.35 µs1.00× (like-for-like reference)
TKS per-call API¹ (DE440)0.188 s0.0171 ms1.71 µs1.27× slower
Swiss — C library, SWIEPH|SPEED (pyswisseph default flags: also computes speeds)0.266 s0.0241 ms2.42 µs0.56×
Swiss — via Python (pyswisseph, default flags)²0.291 s0.0265 ms2.64–2.71 µs0.51×
Swiss (Moshier fallback) — not re-run1.260 s0.1146 ms11.45 µs—
TKS-EPH v4 — batched 8/lane (NEON) — not re-run——0.010 µs4.4× vs per-instant (measured earlier)
¹ The public helper apparent_direction() fetches the Earth state per call; the production pipeline shares Earth/Sun per epoch and uses two light-time iterations. ² Python→C overhead of pyswisseph ≈ 0.25 µs/call (2.64–2.71 µs via Python vs 2.42 µs in C, same flags). Swiss is not thread-safe, so no multi-core row. The C figures come from scripts/bench_swiss_c.c (the libswe inside the pyswisseph wheel, real .se1 files, returned flags confirm file mode); three runs: 1.346 / 1.356 / 1.358 µs position-only. The earlier version of this page compared against Swiss through Python with speeds (7.8×); that mixes in Python overhead and extra work Swiss does and TKS's benchmark does not, so the fair headline is 3.9×.
What changed since the previous version of this table: (a) the precession + 77-term nutation rotation is built once per epoch instead of ≈13× — the three "ordinary" TKS rows used to be equal (1.1–1.5 µs) because that, not the ephemeris, was the cost; (b) the engine can read the fitted TKS-EPH-2 file; (c) deflection, time-scale and sidereal-time corrections (accuracy fixes, no speed effect). Fidelity vs DE440 (max |Δ|, mas): TKS-EPH-2 ≤ 0.33 (Sun) · 0.12 (Moon) · 0.2 (Venus) · ≤ 0.11 others; TKS-EPH-1: Moon 101.7, Sun 35, true node 367. Correctness: true Rāhu agrees with Swiss to < 0.01° in the earlier comparison.

3 · Jyotiṣa page — end-to-end (25 computations)

The /tks-jyotish page issues 25 parallel computations (vara · chalit · 16 vargas · upagraha · Vimśottarī 3 levels · ṣaḍbala · aṣṭakavarga · maitrī · jaimini · doṣa · rāja/nābhasa-yoga · chara/nārāyaṇa/sudarśana dāśās · yoga-samuh · aṣṭottarī · gochara · kālacakra) for one birth. Re-measured on 2026-10-08, 300 page loads (25 connections each, HTTP/1.0 Connection: close; macOS runs out of ephemeral ports beyond ≈16k connections, hence 300 instead of 1,000).

Metricminp50p90p99maxmeanthroughput
Full page (25 endpoints)6.50 ms7.45 ms8.2210.9212.767.54 ms132.7 /s
History of this number. The previous table said p50 12.45 ms. Adding the classical kāla/ceṣṭā-bala inputs to the natal snapshot (tomorrow’s sunrise + the weekdays of the last two saṅkrāntis ⇒ three more sunrise solves) made the page slower (26.4 ms; the light endpoint 2.5 → 6.4 ms) even while raw ephemeris speed went up 7.8×, because a page request is dominated by sunrise search, not by planet positions. Four changes fixed that: (1) the rise/set search scans at 10 min instead of 2 min below ±60° latitude (poles keep the fine scan) — sunrise_sunset 1.55 → 0.42 ms with results identical to < 1 ms (tests/rise_set_scan.rs); (2) rise/set results are memoised per place and date; (3) the natal snapshot is computed once per birth and shared by all 25 endpoints (concurrent identical requests wait on one computation); (4) the last saṅkrānti is taken from the precomputed sankranti.bin and refined in a ±2 min bracket (22 bisections instead of 44 from a 12-day window; bit-identical results on 60 random births). Measured effect: a request for a new birth (every request a cache miss) now takes maitrī 2.1 ms · ṣaḍbala 1.9 ms · sudarśana 2.8 ms (p50) — i.e. back to the level of the committed build of 2026-10-07 (2.5 / 2.6 / 3.4 ms) while still computing the classical bala inputs; with the snapshot already cached, maitrī is 0.19 ms and sudarśana 1.09 ms. Of the gain, the snapshot cache accounts for most of the page figure; the saṅkrānti catalogue saves only ≈ 0.3 ms per cache miss (bisection was never the expensive part).

4 · Concurrency

endpoint (10 concurrent clients, 1,000 identical requests)req/s nowmean latency nowreq/s, build of 2026-10-07failed
sudarśana3,0333.2 ms1,5440
maitrī6,8721.4 ms3,2280
Driven by a Python thread pool (not ab: ApacheBench stalled against this server on the current macOS, so the earlier ab figures of 1,646 / 2,364 req/s are not comparable). Identical requests mostly hit the snapshot cache; the client is the limiting factor for the light endpoint. Compare the two builds, not the absolute numbers.

5 · Reproduction

# 1. Ephemeris, 10,000 x 11 (TKS)
cargo build --release --example bench_11 -p tks-ephemeris
./target/release/examples/bench_11

# 2. Swiss Ephemeris (real .se1 files), same 10,000 x 11
TKS_SWISS_EPHE=/path/to/ephe  /tmp/swevenv/bin/python scripts/bench_swiss.py

# 3. Full jyotisa page (25 endpoints) + concurrency
./target/release/panchanga --serve --port 8099 &
BENCH_PAGE_LOADS=300 python3 scripts/bench_page.py   # 1000 loads exhaust macOS ephemeral ports
# concurrency: 10 client threads x 1000 requests (python http.client), as in the table above
# TKS-EPH-2 vs Swiss (same machine): cargo run --release -p tks-ephemeris --example bench_tks_eph2 ; python scripts/bench_swiss.py

6 · TKS-EPH-1 · 100-year kernel

Kerneltks-eph-1_1950-2050.tkseph — ±50 years (100-yr), 10 bodies (Sun · Moon · Mercury…Pluto; Rāhu/Ketu derived)
FormatChebyshev coefficients, f64 (velocity by differentiation; no extra storage)
Size1.93 MB (compact v3) — first-difference + i32 quantisation, 64-interval re-basing; 2× smaller than f64
Reader speed1.97× faster than the full DE440 kernel (0.038 s vs 0.074 s per 10,000 × 11, re-measured 2026-10-08; with the per-epoch reduction the reader is no longer the cost — TKS-EPH-2 runs at the same speed)
Fidelity (vs DE440)geocentric apparent-longitude residual rms 0.0067″; maximum residual 0.10″ (Moon); Sun 0.035″; true node 0.37″; all other planets < 0.001″. TKS-EPH-2 (the long-span fit) is 300–1000× tighter for Sun/Moon/node. Status: TKS-EPH-1 is kept as the small reference kernel (and WASM demo); no live page or the engine reads it — the browser uses the tiled kernels, the engine uses DE440 and TKS-EPH-2.
Representation residualthe compact BSP reproduces the source state vectors with rms 0.5 km · max 9.4 km (Sun); Earth & Moon ≈ 0.3 m
vs SwissSwiss compresses (quantised integer deltas) to ≈ 0.3 MB / 100 yr; f32 here ≈ 1.5 MB
Generated by gen_eph100 from the DE440 source kernel; read back by the tks_eph reader (implements the engine's Ephemeris trait). The Moon dominates the size (short interval); quantisation à la Swiss would shrink it ~10×.

7 · Precomputed catalogue & WebAssembly

30,000-year catalogue428 MB grid + 427 MB transitions · 55.9 M events · cover 11,000 BCE – 17,000 CE; query **~97 µs** (mmap + binary search)
Catalogue lookup (grid)0.7 ns per day's nine grahas (memory-mapped, O(1))
Transition search~85 ns — binary search over 186,211 boundaries (log₂ ≈ 18)
vs live compute~200× faster (19.8 µs/day live vs nanosecond catalogue)
Catalogue fidelityrms 0.0197″ · max 0.0549″ vs live; 0 index mismatch (tithi·nakṣatra·yoga·karana)
WebAssembly reader21 KB dependency-free module — positions computed client-side, server-free
The 100-year catalogue (daily graha grid + tithi·nakṣatra·yoga·karana·vāra indices + exact transition instants) is memory-mapped and answers any date in nanoseconds; a 21 KB WebAssembly build runs the same kernel entirely in the browser (no server).

In-browser pañcāṅga (client-side, zero network)

Kerneltks_panch_eph.bsp — ±200 yr, 27 bodies — 9 grahas + 16 massive asteroids + Chitra/Lahiri ayanāṃśa (compact Chebyshev, v6: 3.38 MB / 2.57 MB brotli; v4 longitude-only 2.0 MB), residual rms 0.00002°, max 0.00252°
panchanga()0.061 ms — tithi/nakṣatra/yoga/karaṇa, vāra, sunrise/sunset, lagna, rāśi
catLike()0.093 ms — full catalogue payload: māsa, saṃvat, ayana, phase, ends, planets
ephemLike()0.301 ms — 7 grahas + sunrise/sunset + moonrise/set + bhadrā (parallax, Meeus Ch.15)
Core paint (Compute → hero)~90–120 ms (browser DOM/render — not computation)
Date-change → new pañcāṅga~50 ms
Server calls (core)0 to /v1/tks/ephemeris & /v1/tks/limbs; identical to the server (sunrise ±7 s, sunset ±2 s, moonrise/set & bhadrā exact)
The ±200-year nirayana-longitude kernel is loaded once (wasm + service-worker cache); thereafter the whole core pañcāṅga — five limbs, sunrise/sunset, moonrise/set, vāra, lagna, graha rāśi, māsa, saṃvat, ayana, ayanāṃśa, bhadrā — is computed in the browser with no server round-trip. Outside ±200 yr it fetches the one tile covering the date (see below) — still client-side.

Tiled 30,400-year kernel (v6 · int16 + brotli)

Coveragetks-eph/tiles/tile_*.bsp — 76 tiles × ±200 yr = J2000 ±15,200 (30,400 yr), 27 bodies (9 grahas + 16 asteroids + Chitra/Lahiri ayanāṃśa)
FormatTKSEPH6 — int16 coefficient deltas (half of v5's i32); residual rms 0.00002°, max 0.00252° (unchanged)
Size3.38 MB raw → 2.19 MB brotli per tile; whole set 257 → 166 MB (before int16/brotli: 6.56 MB/tile, 499 MB)
Breakdown (166 MB)Moon ~56 · asteroids ~38 · Rāhu+Ketu ~28 · Mercury ~19 · Venus ~8 · Mars ~6 · Jup+Sat ~6 · Sun ~3 · ayanāṃśa ~0.6 MB
Per viewonly the one tile covering the date is fetched (then cached); ±200 yr always resident
Far-era first call24 ms (tile fetch + wasm init + whole pañcāṅga); steady 0.081 ms
vs SwissSwiss .se1 set (present, 100 files) = 94 MB planets+Moon, no asteroids; same ten bodies ≈ 99 MB (TKS) — comparable; TKS also has 16 asteroids + nodes + ayanāṃśa
The 30,400-yr span is served as tiles; the browser fetches only the ±200-yr tile covering the requested date, so far-era dates compute client-side in the same time as the present. int16 coefficient deltas halve the kernel; brotli on top, served with Content-Encoding: br.

Hipparcos star table (117,955 stars)

Tabletks-eph/tks_stars.bin — 117,955 Hipparcos stars, 24 B/star (HIP id · RA/Dec @ J1991.25 · proper motion · V mag)
Size2.83 MB raw → 1.98 MB brotli (served Content-Encoding: br)
Date-independencestatic catalogue; client applies proper-motion + IAU-2006 precession once per date (Spicā → nirayana 180.00°)
vs SwissSwiss default fixed-star catalogue = fixstars.cat 1,259 stars (116 KB) (named sefstars.txt 1,590, 134 KB); no full Hipparcos — TKS carries ~94× more stars, ~24 B/star vs ~92 B/star text
The full Hipparcos catalogue ships in 2.83 MB (24 B/star); sorted by HIP so a lookup is a binary search, and the whole table is fetched once for the star panel.

8 · Naming convention & HTTP architecture

Product naming. The engine's own ephemeris is the TKS Ephemeris — series TKS-EPH-N, file tks-eph-<N>_<first>-<last>.tkseph (e.g. tks-eph-1_1950-2050.tkseph = 100-year, tks-eph-2_1550-2650.tkseph = long-span fit). It is built from JPL DE440 source data (provenance only); product and file naming follow the project's TKS convention.
Architecturelatency (p50)network round-tripsnote
25 separate requests (parallel)12.91 ms25server-side parallelism across threads
Single batch endpoint /v1/vedic/kundali-all11.26 ms1one snapshot + Rayon-parallel parts

Zero-serialization binary payload

Representationbytesnote
Full JSON (/v1/vedic/graha-sphuta)8,044every avasthā field as text
Binary /v1/vedic/positions-bin869 grahas (f64) + ayanāṃśa, application/octet-stream
The binary payload packs the nine nirayana longitudes and the ayanāṃśa as raw little-endian f64 — 86 bytes against 8,044 bytes of the equivalent JSON (~94× smaller). It removes float→string formatting on the server and string→float parsing on the client (the "zero-serialization" win), and reads directly with DataView / Float64Array. Layout: "TKSB" + ver:u8 + n:u8 + n×f64 + ayanāṃśa:f64. The batch endpoint returns all 25 computations as one JSON, sharing a single snapshot and parallelising the parts (1 round-trip vs 25).

9 · Head-to-head — TKS vs Swiss

TKS Ephemeris (TKS-EPH-1 / -2)Swiss Ephemeris 2.10.03
Size1.9 MB (100-yr) · 166 MB (30,400-yr tiled, brotli; 2.19 MB/tile)94 MB (long-range `.se1`, planets+Moon) · ~30 MB (600-yr) · ~3 GB (JPL mode)
Source transparencydocumented binary formats (TKS-EPH-1: FORMAT.md; TKS-EPH-2: specification supplied with the licence); source data JPL DE440 (public) creditedlibrary open-source; .se1 compressed format; DE data via Astrodienst
LicenseTKS-EPH-2 core, engine, catalogues and API: commercial licences (free evaluation build 1950–2050); TKS-EPH-1: TKS-EPHEMERIS LICENSE 1.0; source data (JPL DE440) publicAGPL-3.0 (or commercial licence from Astrodienst)
Architecturenative Rust, zero FFI; WebAssembly build (21 KB)C library (FFI from Rust/Go/Python)
Speed (11-body, 110k)0.038 s (1-thread, TKS-EPH-2) · 0.004 s (14 cores)0.148 s (C library, file mode, positions only) · 0.266 s with speeds · 0.291 s via Python
Bodies10 bodies + true node · 16 massive asteroids (Ceres…Interamnia) · 117,955 Hipparcos stars (via the small-body + Hipparcos catalogues)Sun … Pluto + nodes, Chiron, 620k+ asteroids, fixed stars (mostly faint numbered asteroids)
TKS is a compact, TKS-named kernel built on public JPL DE440 data, with an open format and a native-Rust / WebAssembly stack (no FFI, server-free option); Swiss is the long-standing industry C library — broader in bodies and span, under AGPL / commercial terms. Both are accurate to sub-arcsecond for the classical bodies.

10 · Methodology

Warm-up: 30–50 iterations discarded; kernel pages and CPU caches resident.
Iterations: 10,000 × 11 for ephemeris; 300 page loads and 1,000 concurrent requests for the page.
Statistics: full latency distribution (min·p50·p90·p99·max·mean) for the page; best-of-three for the ephemeris micro-runs (variance < 3 %).
Fairness: identical bodies, epoch grid and iteration count; Swiss in file mode; the engine comparison counts the corrections each engine performs (light-time, aberration, solar deflection, true node).
Scope: server rows include HTTP/TCP setup (HTTP/1.0, Connection: close); ephemeris rows measure pure computation.
संस्करणः bin-1795527110