Closed Bug 596676 Opened 14 years ago Closed 14 years ago

Make the JavaScript shell print out how long it takes to run a script

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: billm, Assigned: billm)

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file, 1 obsolete file)

For simple testing on the command line, it would be nice to print out how long it took to run a script. Doing 'time js ...' is pretty inaccurate.
Attached patch fix (obsolete) — Splinter Review
This adds a command line option to the shell so that running 'js -p ...' prints out a line like the following:
  runtime = 19374 ns
I find it useful.
Assignee: general → wmccloskey
Status: NEW → ASSIGNED
Attachment #475565 - Flags: review?(dmandelin)
Comment on attachment 475565 [details] [diff] [review]
fix

Nice idea. I've been putting "var t0 = new Date; print(new Date - t0)" into test files for months.

>+            if (!compileOnly) {
>+                int64 t1 = PRMJ_Now();
>                 (void)JS_ExecuteScript(cx, obj, script, NULL);
>+                int64 t2 = PRMJ_Now() - t1;
>+                if (printTiming) printf("runtime = %ld ns\n", t2);
>+            }

- PRMJ_Now returns microseconds, so you probably means "us" for the unit. But maybe it would be better to print ms with a fractional digit or two?

- I think "%lld" is what does with JSInt64. 

- Style nit: |if (printTiming) printf("runtime = %ld ns\n", t2);| must be two lines:

    if (printTiming)
        printf("runtime = %ld ns\n", t2);
Attachment #475565 - Flags: review?(dmandelin)
Attached patch updated patchSplinter Review
OK, now with less brain damage.
Attachment #475565 - Attachment is obsolete: true
Attachment #475574 - Flags: review?(dmandelin)
Comment on attachment 475574 [details] [diff] [review]
updated patch

Use PRMJ_USEC_PER_MSEC instead of 1000. Otherwise, r+.
Attachment #475574 - Flags: review?(dmandelin) → review+
http://hg.mozilla.org/mozilla-central/rev/f7206e5fe349
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: