jasmine-node icon indicating copy to clipboard operation
jasmine-node copied to clipboard

Slow Uint8Array comparison

Open appy-one opened this issue 3 years ago • 1 comments

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 avatar Jun 04 '21 12:06 appy-one

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

appy-one avatar Jun 04 '21 12:06 appy-one