Script Preparation code:
x
 
Array.from(Array(100).keys()).map((i) => ({
  id: i+1,
  name: 'Bar',
  asd: 123123
}));
Array.from(Array(50).keys()).map((i) => ({
  id: i+5,
  title: 'Bar',
  age: 12
}));
Tests:
  • Object based

     
    const normalizeLiveUpdateData = (
      newData, 
      oldaData
    ) => {
      if (!oldAnnotations) return newAnnotations;
      const ids = [];
      const data = {};
      oldAnnotations.forEach((a) => {
        ids.push(a.id);
        data[a.id] = a;
      });
      newAnnotations.forEach((a) => {
        if (ids.indexOf(a.id) === -1) {
          ids.push(a.id);
        }
        data[a.id] = a;
      });
      return ids.map(id => data[id]);
    };
  • Array based

     
    const normalizeLiveUpdateData = (
      newAnnotations, oldAnnotations) => {
      if (!oldAnnotations) return newAnnotations;
      let normalizedAnnotations = oldAnnotations;
      newAnnotations.forEach((newAnnotation) => {
        const existingAnnotation = oldAnnotations.find((oldAnnotation) => oldAnnotation.id === newAnnotation.id);
        if (existingAnnotation) {
          normalizedAnnotations = normalizedAnnotations.map(obj => newAnnotations.find(o => o.id === obj.id) || obj);
        } else {
          normalizedAnnotations.push(newAnnotation);
        }
      });
      return normalizedAnnotations;
    };
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Object based
    Array based

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Safari/605.1.15
Safari 14 on Mac OS X 11.0
View result in a separate tab
Test name Executions per second
Object based 274453888.0 Ops/sec
Array based 266871152.0 Ops/sec