Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in nativeVsLodash.js when benchmarking _.replace #3

Open
victor-homyakov opened this issue Oct 27, 2020 · 1 comment
Open

Bug in nativeVsLodash.js when benchmarking _.replace #3

victor-homyakov opened this issue Oct 27, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@victor-homyakov
Copy link
Contributor

Expected behaviour

Benchmark for replace should compare operations on the same string txt

replaceSuite
  .add('lodash', () => _.replace(txt, re, 'oranges'))
  .add('native', () => txt.replace(re, 'oranges'))

Actual behaviour

_.replace tries to make a replacement on non-existent string str and silently fails. Therefore there is no actual comparison for replace.

replaceSuite
  .add('lodash', () => _.replace(str, re, 'oranges'))
  .add('native', () => txt.replace(re, 'oranges'))

How to reproduce

  1. node nativeVsLodash.js
  2. Note that there is no speed output for lodash, and native is marked both as the fastest and the slowest:
	Benchmark: replace
The fastest is native
The slowest is native

Possible solution(s)

Fix the code:

replaceSuite
  .add('lodash', () => _.replace(txt, re, 'oranges'))
  .add('native', () => txt.replace(re, 'oranges'))

Also, the RegExp in this suite is global - this may affect results.

Environment

  • Version:
  • OS(s):
  • Browser(s) (if applicable):
  • Node version:
  • NPM version:

Link or repo

https://github.com/Berkmann18/NativeVsUtils/blob/master/nativeVsLodash.js#L395-L396

@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.98. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant