3 ms·
Generators probably only add overhead here since there is nothing asynchronous happening. You can just as well wrap the first version in a function and return a
by ricardobeat 6y ago
Generators probably only add overhead here since there is nothing asynchronous happening. You can just as well wrap the first version in a function and return an array:
xpath("//text()[contains(., 'Hello')]").forEach(...)
- gridlockd 6y agoGenerators/Iterators are not just for asynchronous code. Generators may be a bit slower than iterating over an array, but arrays use more memory and put more pressure on the garbage collector. Your mileage will vary.
- deleted 6y ago[deleted]
- ricardobeat 6y agoTrue, though I suspect the impact in the case of a node list is negligible; in quick tests I couldn't detect any meaningful difference even while looping through 10k DOM elements.