jasmine-node
jasmine-node copied to clipboard
Slow Uint8Array comparison
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();
Sorry, possibly posted in the wrong repository. I'm using the standard jasmine package from npm (v3.7.0)