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

Slow Uint8Array comparison #446

Open
appy-one opened this issue Jun 4, 2021 · 1 comment
Open

Slow Uint8Array comparison #446

appy-one opened this issue Jun 4, 2021 · 1 comment

Comments

@appy-one
Copy link

appy-one commented Jun 4, 2021

While creating unit tests for AceBase, I had to compare whether stored binary data equals the generated data, which is 5MB large. The expect comparison method is very slow, takes about 5 seconds:

// Generate data
let data = new Uint8Array(5 * 1000 * 1000);
for(let i = 0 ; i < data.length; i++) { data[i] = i % 255; }
// .. Store in the database & retrieve it again into variable 'stored'
expect(stored).toEqual(data); // <-- SLOW

If I compare the data myself with a loop, this is way faster (takes few ms):

let isEqual = true;
for(let i = 0; i < data.length && isEqual; i++) {
   isEqual = data[i] === stored[i]; 
}
expect(isEqual).toBeTrue();
@appy-one
Copy link
Author

appy-one commented Jun 4, 2021

Sorry, possibly posted in the wrong repository. I'm using the standard jasmine package from npm (v3.7.0)

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

1 participant