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

objectEqual Sorts Keys Before Compare #55

Open
xee5ch opened this issue Jul 14, 2018 · 2 comments
Open

objectEqual Sorts Keys Before Compare #55

xee5ch opened this issue Jul 14, 2018 · 2 comments

Comments

@xee5ch
Copy link

xee5ch commented Jul 14, 2018

Today, when reserving the objectEqual function in this library while evaluating deep.equal call stacks in a chai test harness, I observed that when comparing objectEqual() from the default branch in extensiveDeepEqualByType) it sorts the keys.

leftHandKeys.sort();

rightHandKeys.sort();

Is it not more performant for large objects to just iterate over unsorted properties with something like hasOwnProperty on the rightHandProperty properties? If so, I can make a PR.

@keithamus
Copy link
Member

keithamus commented Jul 14, 2018

Hey @xee5ch thanks for the issue!

Is it not more performant for large objects to just iterate over unsorted properties

Great question! I don't know the answer to that. We have a benchmark suite already set up so you could have a go at running the benchmarks, modifying the code and rerunning the benchmarks. I'd be interested to see what happens! And we'd welcome a PR to make things faster!

@xee5ch
Copy link
Author

xee5ch commented Jul 14, 2018

Ok let me review the documentation about running the benchmark suite. I was talking with that friend when stepping through the functions called via chai and I presume it does not make a large difference for small objects, but large object comparison could be slow if you sort the keys of both objects.

I will work on a test case, then post back with samples, the benchmark difference, and of course the code change required.

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

No branches or pull requests

2 participants