Repository navigation
doctor: advise $EPOCHREALTIME over external $(date) for timing scripts - #241
Merged
Merged
Conversation
#201) $(date +%s%N) spawns date.exe per call (~10-30ms on Windows), while the bash 5 builtins $EPOCHREALTIME / $EPOCHSECONDS expand in microseconds with GNU-compatible format (1699999999.123456). rubash already implements both; add a niu doctor advisory row, regression tests pinning format / date +%s agreement / live monotonic updates / the speed gap, and a CHANGELOG entry. closes #201
caomengxuan666
added a commit
that referenced
this pull request
Oct 10, 2026
…notes draft (#254) - Version 1.3.4 -> 1.4.0 (workspace root + crates/niubash-runtime; Cargo.lock synced; internal niubash-runtime dep requirement aligned 1.2.5 -> 1.4.0). The rubash engine requirement stays 1.3.4: it is semver-open (^1.3.4 admits the engine's 1.4.0), and the committed [patch] resolves it to the local ../rubash worktree, whose Cargo.toml still says 1.3.4 until the engine cuts its own release. - CHANGELOG: the Unreleased section becomes [1.4.0] - 2026-10-10. Also repairs the committed merge damage from #243 (stray conflict marker and the #241 doctor-advice entry glued onto the carapace entry) and folds in the merged cycle: #235 #239 #246 #247 #250 #251 #252 #253 plus a compact rubash 1.4.0 engine summary. #240's P2-batch content stays under [1.3.4] where the file already records it (no dup). - docs/release-notes-1.4.0-draft.md: zh+en draft release notes (Added / Fixed / Performance), winuxcmd #1151/#1154-#1157 marked as in-flight for the coordinator, plus the local verification log: release build PASS (niu.exe 10.6 MB), MSIX packed unsigned with a placeholder identity (5.1 MB), wpm-source main carries all four preinstall packages, and cargo publish --dry-run chain findings (rubash -> niubash-runtime -> niubash, blocked on the engine's crates.io release). No tag, no release workflow trigger, no in-flight PRs merged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
$(date +%s%N)每次调用要创建外部 date.exe 进程(本机冷启动实测首次 ~20ms/次),而 bash 5 内建$EPOCHREALTIME/$EPOCHSECONDS微秒级展开。计时脚本应使用内建变量。实测结论(本 PR 依赖)
niu(rubash 引擎)已实现两个变量,格式与 GNU bash 5 一致,无需引擎改动:
$EPOCHREALTIME=1699999999.123456(整数秒.6 位微秒),动态更新、单调递增$EPOCHSECONDS= 纯整数秒,与外部date +%s秒级一致(diff=0)因此本 PR 只做产品侧收尾:文档提示 + 回归测试钉住契约。
改动
niu doctor新增 timing 提示行:「计时脚本用$EPOCHREALTIME代替$(date +%s%N)」,说明各自量级;tests/issue201_epochrealtime.rs(4 个测试,全过):RT正则^\d+\.\d{6}$、EPOCHSECONDS纯整数、整数部分相等);date +%s及宿主时钟的秒级一致性;${EPOCHREALTIME/.}差值落在微秒区间);$(date +%s%N)vs$EPOCHREALTIME≥50x,CI 容忍抖动);Unreleased/Added条目。基准(本工作树 debug 构建,300 次循环,
${EPOCHREALTIME/.}计时)x=$(true)x=$(echo abc)x=$(date +%s%N)x=$EPOCHREALTIME稳态约 25x;冷启动( Defender/首次进程创建,即 issue 复现的 31ms/次场景)差距达数百倍。微秒精度验证:
sleep 0.05前后差值 ≈50000µs。验证
cargo test --test issue201_epochrealtime→ 4 passedcargo fmt -- --check通过niu doctor输出新行正常closes #201