W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2013

RE: How to correctly spec sequences requiring an iterable

From: Domenic Denicola <domenic@domenicdenicola.com>
Date: Mon, 18 Nov 2013 18:19:11 +0000
To: Boris Zbarsky <bzbarsky@MIT.EDU>, "public-script-coord@w3.org" <public-script-coord@w3.org>
Message-ID: <a5e73094de2347ffa0b31e4b6ef4160c@BN1PR05MB325.namprd05.prod.outlook.com>
From: Boris Zbarsky <bzbarsky@MIT.EDU>

> But maybe I misunderstand the performance cost you're worrying about?

Well, I'm not sure, so let me restate it just in case.

Let's say I pass a sequence containing 1000 numbers to such a function. Your proposed behavior is, from what I understand,

```js
function frobEachElement(sequence) {
  var array = [];
  for (var el of sequence) {
    array.push(Number(el));
  }

  array.forEach(frob);
}
```

So you do a total of 2000 iterations. Whereas the "idiomatic" way would be

```js
function frobEachElement(sequence) {
  for (var el of sequence) {
    frob(Number(el));
  }
}
```

which only does 1000 iterations.

Thoughts?
Received on Monday, 18 November 2013 18:20:01 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:19 UTC