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

replaced indexOf with startsWith where required to improve performace #2031

Closed
wants to merge 1 commit into from

Conversation

clintonyeb
Copy link

The source code makes a lot of checks to make sure a string starts with *0x". If this is true, the string is treated as a hash value or a number otherwise.

However using indexOf to test for this is inefficient as compared to its equivalent startsWith.

Here is a small benchmark test:

Here is the GitHub Gist: web3_indexof_starts_with.js

To verify the results, run:

$ node web3_indexof_starts_with.js

Testing startsWith:::
Benchmark took 1834165 nanoseconds
Completed startsWith.

Testing indexOf:::
Benchmark took 2679461 nanoseconds
Completed indexOf.

Thanks.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 90.476% when pulling 4210dfb on clintonyeb:develop into 215e33c on ethereum:develop.

@nivida nivida added the 0.x.x label Nov 18, 2018
@nivida
Copy link
Contributor

nivida commented Nov 18, 2018

It would be cool if you could submit also a PR for the 1.0 version. If you will do this then please to it in the ethereumProvider branch because the architecture of web3.js has changed a lot there :)

@nivida
Copy link
Contributor

nivida commented Apr 16, 2019

Closed because the latest maintenance release was 0.20.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants