跳至内容
基准测试

基准测试

项目有两套独立的基准测试,用途不同:

持续基准测试——源代码及结果位于 https://github.com/ringsaturn/tz-benchmark, 可视化展示在 https://ringsaturn.github.io/tz-benchmark/。 每次发布时在 GitHub Actions 中自动运行,用于跨包对比。 由于 GitHub Actions 运行器与开发者机器硬件不同,绝对数值与本地运行有所差异,但包之间的相对趋势可以说明问题。

本地基准测试——以下表格在搭载 Apple M3 Max 的 MacBook Pro 上测得。 这些结果更能反映现代硬件上真实场景的延迟。

测试方法

每个查找器初始化一次并复用于所有查询,匹配推荐的生产环境模式。 查询使用全球城市坐标的代表性样本加上特意选取的边界边缘案例点。

Go (tzf v1.1.0)

目标数据集场景中位数 (ns)p99 (ns)吞吐量 (ops/s)内存 (MiB)
DefaultFindertopology-simplified + preindexedge case · GetTimezoneName3000.03000.0393.5K74.70
Findertopology-simplifiededge case · GetTimezoneName2000.03000.0470.4K66.00
FullFinderfull-precision + preindexedge case · GetTimezoneName3000.03000.0395.6K421.50
Finderfull-precisionedge case · GetTimezoneName2000.03000.0475.3K412.70
DefaultFindertopology-simplified + preindexrandom world cities · GetTimezoneName1000.04000.01162.4K74.70
FuzzyFinderpreindexrandom world cities · GetTimezoneName469.81000.02128.6K8.90
Findertopology-simplifiedrandom world cities · GetTimezoneName2000.04000.0531.6K66.00
FullFinderfull-precision + preindexrandom world cities · GetTimezoneName1000.04000.01143.1K421.50
Finderfull-precisionrandom world cities · GetTimezoneName2000.05000.0468.6K412.70
DefaultFindertopology-simplified + preindexrandom world cities · GetTimezoneNames5000.09000.0208.0K74.70
FuzzyFinderpreindexrandom world cities · GetTimezoneNames462.71000.02161.2K8.90
Findertopology-simplifiedrandom world cities · GetTimezoneNames5000.08000.0211.5K66.00
FullFinderfull-precision + preindexrandom world cities · GetTimezoneNames5000.09000.0192.8K421.50

Rust (tzf-rs v1.2.0 / v1.3.0)

拓扑简化(默认内置)

目标数据集场景中位数 (µs)吞吐量 (ops/s)内存 (MiB)
Findertopology-simplifiedYStripes only1.2296813,273103.30
Findertopology-simplifiedNo index6.5402152,90151.68
DefaultFindertopology-simplified + preindexYStripes only1.1383878,503125.98
DefaultFindertopology-simplified + preindexNo index2.2514444,16877.79

完整精度(可选 full feature)

目标数据集场景中位数 (µs)吞吐量 (ops/s)内存 (MiB)
Finder (full)full-precisionYStripes only2.0852479,570561.08
Finder (full)full-precisionNo index37.698026,527252.54
DefaultFinder (full)full-precision + preindexYStripes only1.3488741,400584.30
DefaultFinder (full)full-precision + preindexNo index11.275088,692278.63

Python (tzfpy v1.2.0)

tzfpy 是基于 tzf-rs 的 PyO3 绑定。基准测试使用 pytest-benchmark 测量 单次 get_tz() 调用(随机坐标,拓扑简化数据集)。 结果来自搭载 Apple M3 Max 的 MacBook Pro。

索引模式中位数 (µs)平均值 (µs)吞吐量 (Kops/s)内存
默认(YStripes 启用)1.79341.8321545.8~120 MB
无 YStripes(_TZFPY_DISABLE_Y_STRIPES=12.52132.5338394.7未测量

每次调用开销与原始 Rust 数据相当;与 tzf-rs 数据的差异反映了通过 PyO3 的 Python → Rust FFI 开销。

关键结论

  • YStripes 索引为完整精度 Finder 带来显著提升:从 37.7 µs(无索引)降至 2.1 µs——约 18 倍加速。对拓扑简化数据集效果较小但仍然显著(6.5 µs → 1.2 µs,约 5 倍加速)。
  • DefaultFinder(预索引 + 多边形)在一般工作负载中始终表现最佳:中位数约 1 µs,内存约 75–126 MB,与数据集无关。
  • FuzzyFinder(仅预索引)在约 470 ns 时最快,但仅覆盖完全位于单个时区多边形内部的瓦片。对于靠近边界或未覆盖瓦片的点,它返回空结果而非猜测。仅在你的工作负载已知远离时区边界时单独使用。
  • Python (tzfpy) 在 Rust 基线之上增加了约 0.5–1 µs 的 PyO3 FFI 开销。启用 YStripes 后中位数约为 1.8 µs——在大多数后端 API 预算范围内。
  • 内存随数据集扩展:在 Rust 中从拓扑简化切换到完整精度,启用 YStripes 后内存增加约 450 MB。
最后更新于