tzf-rs: a fast timezone finder for Rust.
NOTE: this package use a simplified shape data so not so accurate around border.
Build options
By default, the binary is built as well. If you don't want/need it, then build like this:
Or add in the below way:
Best practice
It's expensive to init tzf-rs's Finder/FuzzyFinder/DefaultFinder, please consider reuse it or as a global var. Below is a global var example:
use lazy_static;
use DefaultFinder;
lazy_static!
For reuse it,
racemap/rust-tz-service
is a
good example.
A Redis protocol demo could be used here: redizone.
Performance
The tzf-rs package is intended for high-performance geo spatial query services,
such as weather forecasting APIs. Most queries can be returned within a very
short time, averaging around 3000 nanoseconds(there is 1000ns slower compared
with Go repo tzf
and I will continue to improve that, you can track progress
here).
Here is what has been done to improve performance:
- Using pre-indexing to handle most queries takes approximately 1000 nanoseconds.
- Using a finely-tuned Ray Casting algorithm package
ringsaturn/geometry-rs
to verify whether a polygon contains a point.
That's all. There are no black magic tricks inside the tzf-rs.
Below is a benchmark run on global cities(about 14K), and avg time is about 3000 ns per query:
test benches_default::bench_default_finder_random_city ... bench: 2,870 ns/iter (+/- 182)
Criterion result | Pic |
---|---|
Regression |
You can view more details from latest benchmark from GitHub Actions logs.
References
I have written an article about the history of tzf, its Rust port, and its Rust port's Python binding; you can view it here.
- Original Go repo: https://github.com/ringsaturn/tzf
- Binary timezone data: https://github.com/ringsaturn/tzf-rel
- Geometry: use https://github.com/ringsaturn/geometry-rs which is https://github.com/tidwall/geometry's Rust port.
- Continuous Benchmark compared with other packages: https://github.com/ringsaturn/tz-benchmark
Bindings
LICENSE
This project is licensed under the MIT license. The data is
licensed under the
ODbL license, same as
evansiroky/timezone-boundary-builder