Throwing errors on mutating immutable bindings

Isiah Meadows impinball at gmail.com
Mon Oct 6 00:22:44 PDT 2014


Here's what I got from 4 consecutive runs (label prefixes self-explanatory):

```
(SM Native) Time to complete: 15584 microseconds.
(SM Shell)  Time to complete: 512053 microseconds.
(Node V8)   Time to complete: 238188 microseconds.
(SM Native) Time to complete: 17418 microseconds.
(SM Shell)  Time to complete: 556189 microseconds.
(Node V8)   Time to complete: 179156 microseconds.
(SM Native) Time to complete: 16119 microseconds.
(SM Shell)  Time to complete: 528309 microseconds.
(Node V8)   Time to complete: 157015 microseconds.
(SM Native) Time to complete: 16457 microseconds.
(SM Shell)  Time to complete: 470544 microseconds.
(Node V8)   Time to complete: 166123 microseconds.
```

Clearly, we still have a long way to go before beating a C++ parser.
Pretty interesting to think about, though.

(Also, as a side note, should this be profiled for SpiderMonkey? V8 is
averaging about 10x native, SpiderMonkey about 3-5x V8. My spidey
senses sense a growing gap...;-))

-----

Here's the source for each:
```js
// sm-parser.js
if (typeof require !== 'undefined' && typeof process !== 'undefined') {
  throw new Error('Not for Node. Try with SpiderMonkey.');
}

load('./acorn.js');

function getMicroseconds(end, start) {
  return end * 1000 - start * 1000;
}

var jQuerySrc = read('./jquery-2.1.1.min.js');
var parsed, end;
var start = dateNow();
parsed = parse(jQuerySrc);
end = dateNow();
print('(SM Native) Time to complete: ' + getMicroseconds(end, start) +
' microseconds.');
```

```js
// js-parser.js
if (typeof require !== 'undefined' && typeof process !== 'undefined') {
  // Boilerplate for Node.js
  var acorn = require('./acorn.js');
  var dateNow = process.hrtime;
  var read = require('fs').readFileSync;
  var print = console.log;
  var getMicroseconds = function (end, start) {
    // Microsecond precision to match SpiderMonkey
    end = end[0] * 1e9 + end[1];
    start = start[0] * 1e9 + start[1];
    return Math.floor((end - start) / 1000);
  };
  var prefix = '(Node V8)  ';
} else {
  load('./acorn.js');
  var getMicroseconds = function (end, start) {
    return end * 1000 - start * 1000;
  };
  var prefix = '(SM Shell) ';
}

var jsParse = acorn.parse;
var jQuerySrc = read('./jquery-2.1.1.min.js');
var parsed, end;
var start = dateNow();
parsed = jsParse(jQuerySrc);
end = dateNow();
print(prefix + ' Time to complete: ' + getMicroseconds(end, start) + '
microseconds.');
```

On Mon, Oct 6, 2014 at 3:02 AM, Isiah Meadows <impinball at gmail.com> wrote:
> CC the list... :(
>
>
> ---------- Forwarded message ----------
> From: Isiah Meadows <impinball at gmail.com>
> Date: Mon, Oct 6, 2014 at 2:19 AM
> Subject: Re: Throwing errors on mutating immutable bindings
> To: Till Schneidereit <till at tillschneidereit.net>
>
>
> Thank you. I was looking for something I could benchmark in native
> code, but this works. It shouldn't be hard to test side by side. I'll
> get back with my results.
>
> On Sun, Oct 5, 2014 at 7:32 PM, Till Schneidereit
> <till at tillschneidereit.net> wrote:
>> On Sun, Oct 5, 2014 at 7:24 AM, Isiah Meadows <impinball at gmail.com> wrote:
>>>
>>> If I can find a native parser (that only parses), I would run benchmarks.
>>> Shouldn't take that long to time a few rounds of parsing a large library
>>> like jQuery or React. I would be more than willing to accept pointers on
>>> where to find one.
>>
>> The SpiderMonkey shell lets you do both syntax parsing - the fast initial
>> parse we do to detect static errors, and full parsing; both using the same
>> parser Firefox uses. You can download the latest version here:
>> http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/
>>
>> Or, for non-dev build versions, check one directory up.
>>
>> The shell has a `parse` function for full parsing and a `parseSyntax` for,
>> well, syntax parsing. More information available using `help()`.
>>
>>
>> hth,
>> till
>>
>
>
>
> --
> Isiah Meadows
>
>
> --
> Isiah Meadows



-- 
Isiah Meadows


More information about the es-discuss mailing list