feat(cli): add --time flag to report script execution timing#4711
feat(cli): add --time flag to report script execution timing#4711jedel1043 merged 8 commits intoboa-dev:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4711 +/- ##
==========================================
+ Coverage 47.24% 57.05% +9.81%
==========================================
Files 476 552 +76
Lines 46892 60568 +13676
==========================================
+ Hits 22154 34559 +12405
- Misses 24738 26009 +1271 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Test262 conformance changes
|
|
Hey @jedel1043 just following up here 🙂 This adds a --time flag to the Boa CLI that prints parsing and execution timings to stderr (so it won’t mix with script stdout). It measures parse vs. execution separately for modules and has no runtime overhead when the flag isn’t used. Would appreciate a review from someone on the CLI/runtime side, happy to make any changes if needed. |
jedel1043
left a comment
There was a problem hiding this comment.
Nice! I have a very small suggestion.
d7953b2 to
3cba6cc
Compare
|
I kinda feel like this pattern of struct Timer<'a> {
name: &'static str,
now: Instant,
counters: &'a mut Vec<(&'static str, Duration)>
}
impl Drop for Timer<'a> {
fn drop(&mut self) {
self.counters.push((self.name, self.now.elapsed()));
}
}
struct Counters {
counters: Option<Vec<(&'static str, Duration)>>
}
impl Counters {
fn new_timer(&mut self, name: &'static str) -> Option<Timer<'_>> {
if let Some(counters) = &mut self.counters {
Some(Timer {
name,
now: Instant::now(),
counters
})
} else { None }
}
}
impl Drop for Counters {
// Code to print all timers
}That way, to measure something you just do like {
let _timer = counters.new_timer("Parsing");
// parse
}
// more code |
c38ee61 to
a2a3dbb
Compare
|
Hey @jedel1043, thanks again for the review and the suggestions. I’ve just pushed some updates to address your feedback:
Let me know if this looks good to you or if there's anything else you'd like me to tweak! |
Summary
This adds a
--timeflag to the Boa CLI that prints how long parsing and execution took, similar to what other engines offer (V8'sd8 --times, etc.).When the flag is passed, timing info is printed to stderr so it doesn't interfere with script output on stdout:
$ boa --time script.js Hello, World!
Execution: 1.56ms
For modules, parsing and execution are measured separately:
$ boa --time -m module.mjs 42
Parsing: 1.82ms Execution: 1.27ms Total: 3.09ms
Without the flag, there's zero overhead — no
Instant::now()calls and no extra output.Changes
All changes are in cli/src/main.rs:
--timeboolean flag to the Opt struct (long flag only, since-tis already used by--trace)context.eval()in evaluate_expr and evaluate_file with conditionalInstantmeasurements usingargs.time.then(Instant::now)Module::parse()andload_link_evaluate()are measured separatelycontext.run_jobs()is called unconditionally after eval so async work is always drained regardless of whether timing is enabledNo new dependencies - uses
std::time::Instantwhich was already imported (asDuration) in the file.Closes #4709