fabiospampinato/noop-tag

Usage with `String.raw`

Closed this issue ยท 4 comments

I think this package could utilize the built-in String.raw, which should be faster than the current implementation.

MDN reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw#building_an_identity_tag

IIRC I had tried that at one point and it was actually slower for some reason ๐Ÿค” It's worth a second attempt though, maybe it got optimized since then.

I haven't tried it so you might be right. ๐Ÿ˜… I assumed native implementation should be faster, but that may not be the case.

As of today the built-in way of doing this takes ~500ms in my benchmark, vs the ~70ms that my implementation takes ๐Ÿคทโ€โ™‚๏ธ

This seems to take some ~330ms:

function noop (): string {

  if ( arguments.length < 2 ) return arguments[0];

  arguments[0] = { raw: arguments[0] };

  return String.raw.apply ( String, arguments );

}

It's still way slower than my implementation, so nothing to do here I guess.