mergeDeep

JavaScript performance comparison

Test case created by 19h

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var isObject = function (item) {
      // typeof null is 'object', filter it
      return item !== null
          && typeof item === 'object'
          // arrays are objects, too
          && item.constructor !== Array;
  };
  
  var mergeDeepRec = function (target, source) {
      if (!isObject(target) || !isObject(source)) {
          return target;
      }
      Object
          .keys(source)
          .forEach(function (key) {
          var _a, _b;
          if (isObject(source[key])
              && (!target[key]
                  || isObject(target[key]))) {
              if (!target[key]) {
                  Object.assign(target, (_a = {}, _a[key] = {}, _a));
              }
              mergeDeepRec(target[key], source[key]);
              return;
          }
          Object.assign(target, (_b = {},
              _b[key] = source[key],
              _b));
      });
      return target;
  };
  
  
  var mergeDeepIter = function (target, source) {
      var _a, _b;
      if (!isObject(target) || !isObject(source)) {
          return target;
      }
      var stack = [
          [target, source],
      ];
      while (stack.length !== 0) {
          var frame = stack.shift();
          var target_1 = frame[0];
          var source_1 = frame[1];
          var sourceKeys = Object.keys(source_1);
          for (var i = 0; i < sourceKeys.length; ++i) {
              var key = sourceKeys[i];
              if (isObject(source_1[key])
                  && (!target_1[key]
                      || isObject(target_1[key]))) {
                  if (!target_1[key]) {
                      Object.assign(target_1, (_a = {}, _a[key] = {}, _a));
                  }
                  stack.push([
                      target_1[key],
                      source_1[key],
                  ]);
                  continue;
              }
              Object.assign(target_1, (_b = {},
                  _b[key] = source_1[key],
                  _b));
          }
      }
      return target;
  };
  
  var mergeDeepIter2 = function (target, source) {
      if (!isObject(target) || !isObject(source)) {
          return target;
      }
      var stack = [
          [target, source],
      ];
      while (stack.length !== 0) {
          var frame = stack.shift();
          var target_1 = frame[0];
          var source_1 = frame[1];
          var sourceKeys = Object.keys(source_1);
          for (var i = 0; i < sourceKeys.length; ++i) {
              var key = sourceKeys[i];
              if (isObject(source_1[key])
                  && (!target_1[key]
                      || isObject(target_1[key]))) {
                  if (!target_1[key]) {
                      target_1[key] = {};
                  }
                  stack.push([
                      target_1[key],
                      source_1[key],
                  ]);
                  continue;
              }
              target_1[key] = source_1[key];
          }
      }
      return target;
  };
  
  var d1 = JSON.parse(JSON.stringify({"data":{"substances":[{"class":{"chemical":["Cyclohexanol"],"psychoactive":["Opioid"]},"crossTolerances":["opioids"],"dangerousInteractions":[{"class":null,"name":"MAOI","toxicity":null},{"class":{"chemical":["Arylcyclohexylamine"],"psychoactive":["Dissociatives"]},"name":"Ketamine","toxicity":["exact toxic dosage is unknown"]},{"class":{"chemical":["Arylcyclohexylamine"],"psychoactive":["Dissociatives"]},"name":"Methoxetamine","toxicity":["exact toxic dosage is unknown"]},{"class":{"chemical":["Morphinan"],"psychoactive":["Dissociatives"]},"name":"Dextromethorphan","toxicity":["exact toxic dosage is unknown"]},{"class":{"chemical":["Arylcyclohexylamine"],"psychoactive":["Dissociatives"]},"name":"PCP","toxicity":null},{"class":null,"name":"Substituted amphetamine","toxicity":null},{"class":{"chemical":["Amphetamine","Phenethylamines"],"psychoactive":["Entactogen","Stimulants"]},"name":"MDMA","toxicity":["exact toxic dosage is unknown"]},{"class":{"chemical":["Tropane_alkaloids","Benzoic_acid_ester"],"psychoactive":["Stimulants"]},"name":"Cocaine","toxicity":["individuals have died from as little as 30 mg applied to mucous membranes, whereas addicts may tolerate up to 5 grams daily"]},{"class":{"chemical":["Alcohol"],"psychoactive":["Depressant"]},"name":"Alcohol","toxicity":["Death from ethanol consumption is possible when blood alcohol levels reach 0.4%"]},{"class":{"chemical":["Alcohol"],"psychoactive":["Depressant"]},"name":"GHB","toxicity":["considered to be a safe and non-toxic substance when used responsibly","Doses above 10 grams are associated with a risk of death"]},{"class":{"chemical":["GABA"],"psychoactive":["Depressant"]},"name":"GBL","toxicity":null},{"class":{"chemical":["Tryptamine"],"psychoactive":["Entactogen"]},"name":"ΑMT","toxicity":null},{"class":null,"name":"Opioid","toxicity":null},{"class":null,"name":"Benzodiazepine","toxicity":["low toxicity","potentially lethality increases significantly when mixed with depressants like alcohol or opioids"]},{"class":null,"name":"25x-NBOMe","toxicity":null},{"class":{"chemical":["Phenethylamines"],"psychoactive":["Stimulants"]},"name":"Methylphenidate","toxicity":null}],"effects":[{"name":"Pain relief","url":"https://psychonautwiki.org/wiki/Pain_relief"},{"name":"Physical euphoria","url":"https://psychonautwiki.org/wiki/Physical_euphoria"},{"name":"Itchiness","url":"https://psychonautwiki.org/wiki/Itchiness"},{"name":"Stimulation","url":"https://psychonautwiki.org/wiki/Stimulation"},{"name":"Constipation","url":"https://psychonautwiki.org/wiki/Constipation"},{"name":"Cough suppression","url":"https://psychonautwiki.org/wiki/Cough_suppression"},{"name":"Difficulty urinating","url":"https://psychonautwiki.org/wiki/Difficulty_urinating"},{"name":"Nausea","url":"https://psychonautwiki.org/wiki/Nausea"},{"name":"Sedation","url":"https://psychonautwiki.org/wiki/Sedation"},{"name":"Pupil constriction","url":"https://psychonautwiki.org/wiki/Pupil_constriction"},{"name":"Decreased libido","url":"https://psychonautwiki.org/wiki/Decreased_libido"},{"name":"Appetite suppression","url":"https://psychonautwiki.org/wiki/Appetite_suppression"},{"name":"Orgasm suppression","url":"https://psychonautwiki.org/wiki/Orgasm_suppression"},{"name":"Cognitive euphoria","url":"https://psychonautwiki.org/wiki/Cognitive_euphoria"},{"name":"Anxiety suppression","url":"https://psychonautwiki.org/wiki/Anxiety_suppression"},{"name":"Thought acceleration","url":"https://psychonautwiki.org/wiki/Thought_acceleration"},{"name":"Compulsive redosing","url":"https://psychonautwiki.org/wiki/Compulsive_redosing"},{"name":"Dream potentiation","url":"https://psychonautwiki.org/wiki/Dream_potentiation"},{"name":"Dehydration","url":"https://psychonautwiki.org/wiki/Dehydration"},{"name":"Seizure","url":"https://psychonautwiki.org/wiki/Seizure"},{"name":"Wakefulness","url":"https://psychonautwiki.org/wiki/Wakefulness"},{"name":"Increased music appreciation","url":"https://psychonautwiki.org/wiki/Increased_music_appreciation"},{"name":"Disinhibition","url":"https://psychonautwiki.org/wiki/Disinhibition"},{"name":"Empathy, affection and sociability enhancement","url":"https://psychonautwiki.org/wiki/Empathy,_affection_and_sociability_enhancement"},{"name":"Anxiety","url":"https://psychonautwiki.org/wiki/Anxiety"},{"name":"Motivation enhancement","url":"https://psychonautwiki.org/wiki/Motivation_enhancement"},{"name":"Headache","url":"https://psychonautwiki.org/wiki/Headache"}],"name":"Tramadol","roas":[{"bioavailability":{"max":90,"min":70},"dose":{"common":{"max":250,"min":100},"heavy":300,"light":{"max":100,"min":50},"strong":{"max":300,"min":250},"threshold":25,"units":"mg"},"duration":{"afterglow":null,"comeup":null,"duration":null,"offset":{"max":4,"min":2,"units":"hours"},"onset":{"max":60,"min":15,"units":"minutes"},"peak":{"max":6,"min":2,"units":"hours"},"total":{"max":10,"min":6,"units":"hours"}},"name":"oral"}],"toxicity":["low toxicity","potentially lethal when mixed with depressants like alcohol or benzodiazepines"],"uncertainInteractions":null,"unsafeInteractions":[{"class":{"chemical":["Lysergamide"],"psychoactive":["Psychedelics"]},"name":"LSD","toxicity":["extremely low toxicity relative to dose"]},{"class":{"chemical":["Tryptamine"],"psychoactive":["Psychedelics"]},"name":"DMT","toxicity":["extremely low toxicity"]},{"class":null,"name":"DOx","toxicity":null},{"class":null,"name":"2C-x","toxicity":null},{"class":null,"name":"2C-T-x","toxicity":null},{"class":null,"name":"5-MeO-xxT","toxicity":null},{"class":{"chemical":["Tryptamine"],"psychoactive":null},"name":"Psilocybin mushrooms","toxicity":["extremely low toxicity"]},{"class":{"chemical":["Phenethylamines"],"psychoactive":["Psychedelics"]},"name":"Mescaline","toxicity":["toxic dose is unknown"]}]}]}}));
  
  var d2 = JSON.parse(JSON.stringify({"data":{"substances":[{"class":{"chemical":["Lysergamide"],"psychoactive":["Psychedelics"]},"crossTolerances":["psychedelics"],"dangerousInteractions":null,"effects":[{"name":"Spontaneous bodily sensations","url":"https://psychonautwiki.org/wiki/Spontaneous_bodily_sensations"},{"name":"Stimulation","url":"https://psychonautwiki.org/wiki/Stimulation"},{"name":"Nausea","url":"https://psychonautwiki.org/wiki/Nausea"},{"name":"Muscle twitching","url":"https://psychonautwiki.org/wiki/Muscle_twitching"},{"name":"Tactile enhancement","url":"https://psychonautwiki.org/wiki/Tactile_enhancement"},{"name":"Bodily control enhancement","url":"https://psychonautwiki.org/wiki/Bodily_control_enhancement"},{"name":"Difficulty urinating","url":"https://psychonautwiki.org/wiki/Difficulty_urinating"},{"name":"Increased blood pressure","url":"https://psychonautwiki.org/wiki/Increased_blood_pressure"},{"name":"Increased heart rate","url":"https://psychonautwiki.org/wiki/Increased_heart_rate"},{"name":"Perception of bodily lightness","url":"https://psychonautwiki.org/wiki/Perception_of_bodily_lightness"},{"name":"Physical euphoria","url":"https://psychonautwiki.org/wiki/Physical_euphoria"},{"name":"Pupil dilation","url":"https://psychonautwiki.org/wiki/Pupil_dilation"},{"name":"Addiction suppression","url":"https://psychonautwiki.org/wiki/Addiction_suppression"},{"name":"Analysis enhancement","url":"https://psychonautwiki.org/wiki/Analysis_enhancement"},{"name":"Anxiety","url":"https://psychonautwiki.org/wiki/Anxiety"},{"name":"Conceptual thinking","url":"https://psychonautwiki.org/wiki/Conceptual_thinking"},{"name":"Creativity enhancement","url":"https://psychonautwiki.org/wiki/Creativity_enhancement"},{"name":"Delusion","url":"https://psychonautwiki.org/wiki/Delusion"},{"name":"Déjà vu","url":"https://psychonautwiki.org/wiki/D%C3%A9j%C3%A0_vu"},{"name":"Ego replacement","url":"https://psychonautwiki.org/wiki/Ego_replacement"},{"name":"Emotion enhancement","url":"https://psychonautwiki.org/wiki/Emotion_enhancement"},{"name":"Focus enhancement","url":"https://psychonautwiki.org/wiki/Focus_enhancement"},{"name":"Immersion enhancement","url":"https://psychonautwiki.org/wiki/Immersion_enhancement"},{"name":"Increased libido","url":"https://psychonautwiki.org/wiki/Increased_libido"},{"name":"Increased music appreciation","url":"https://psychonautwiki.org/wiki/Increased_music_appreciation"},{"name":"Laughter fits","url":"https://psychonautwiki.org/wiki/Laughter_fits"},{"name":"Memory suppression","url":"https://psychonautwiki.org/wiki/Memory_suppression"},{"name":"Multiple thought streams","url":"https://psychonautwiki.org/wiki/Multiple_thought_streams"},{"name":"Novelty enhancement","url":"https://psychonautwiki.org/wiki/Novelty_enhancement"},{"name":"Personal bias suppression","url":"https://psychonautwiki.org/wiki/Personal_bias_suppression"},{"name":"Personal meaning enhancement","url":"https://psychonautwiki.org/wiki/Personal_meaning_enhancement"},{"name":"Personality regression","url":"https://psychonautwiki.org/wiki/Personality_regression"},{"name":"Simultaneous emotions","url":"https://psychonautwiki.org/wiki/Simultaneous_emotions"},{"name":"Suggestibility enhancement","url":"https://psychonautwiki.org/wiki/Suggestibility_enhancement"},{"name":"Thought acceleration","url":"https://psychonautwiki.org/wiki/Thought_acceleration"},{"name":"Thought loop","url":"https://psychonautwiki.org/wiki/Thought_loop"},{"name":"Time distortion","url":"https://psychonautwiki.org/wiki/Time_distortion"},{"name":"Unity and interconnectedness","url":"https://psychonautwiki.org/wiki/Unity_and_interconnectedness"},{"name":"Wakefulness","url":"https://psychonautwiki.org/wiki/Wakefulness"},{"name":"Colour enhancement","url":"https://psychonautwiki.org/wiki/Colour_enhancement"},{"name":"Pattern recognition enhancement","url":"https://psychonautwiki.org/wiki/Pattern_recognition_enhancement"},{"name":"Acuity enhancement","url":"https://psychonautwiki.org/wiki/Acuity_enhancement"},{"name":"Drifting","url":"https://psychonautwiki.org/wiki/Drifting"},{"name":"After images","url":"https://psychonautwiki.org/wiki/After_images"},{"name":"Colour shifting","url":"https://psychonautwiki.org/wiki/Colour_shifting"},{"name":"Depth perception distortions","url":"https://psychonautwiki.org/wiki/Depth_perception_distortions"},{"name":"Perspective distortion","url":"https://psychonautwiki.org/wiki/Perspective_distortion"},{"name":"Recursion","url":"https://psychonautwiki.org/wiki/Recursion"},{"name":"Scenery slicing","url":"https://psychonautwiki.org/wiki/Scenery_slicing"},{"name":"Symmetrical texture repetition","url":"https://psychonautwiki.org/wiki/Symmetrical_texture_repetition"},{"name":"Tracers","url":"https://psychonautwiki.org/wiki/Tracers"},{"name":"Geometry","url":"https://psychonautwiki.org/wiki/Geometry"},{"name":"Transformations","url":"https://psychonautwiki.org/wiki/Transformations"},{"name":"Internal hallucination","url":"https://psychonautwiki.org/wiki/Internal_hallucination"},{"name":"Autonomous entity","url":"https://psychonautwiki.org/wiki/Autonomous_entity"},{"name":"Settings, sceneries, and landscapes","url":"https://psychonautwiki.org/wiki/Settings,_sceneries,_and_landscapes"},{"name":"Perspective hallucination","url":"https://psychonautwiki.org/wiki/Perspective_hallucination"},{"name":"Scenarios and plots","url":"https://psychonautwiki.org/wiki/Scenarios_and_plots"},{"name":"External hallucination","url":"https://psychonautwiki.org/wiki/External_hallucination"},{"name":"Auditory enhancement","url":"https://psychonautwiki.org/wiki/Auditory_enhancement"},{"name":"Auditory distortion","url":"https://psychonautwiki.org/wiki/Auditory_distortion"},{"name":"Auditory hallucination","url":"https://psychonautwiki.org/wiki/Auditory_hallucination"},{"name":"Synaesthesia","url":"https://psychonautwiki.org/wiki/Synaesthesia"},{"name":"Stamina enhancement","url":"https://psychonautwiki.org/wiki/Stamina_enhancement"},{"name":"Appetite suppression","url":"https://psychonautwiki.org/wiki/Appetite_suppression"},{"name":"Excessive yawning","url":"https://psychonautwiki.org/wiki/Excessive_yawning"},{"name":"Increased salivation","url":"https://psychonautwiki.org/wiki/Increased_salivation"},{"name":"Seizure","url":"https://psychonautwiki.org/wiki/Seizure"},{"name":"Cognitive euphoria","url":"https://psychonautwiki.org/wiki/Cognitive_euphoria"},{"name":"Increased perspiration","url":"https://psychonautwiki.org/wiki/Increased_perspiration"},{"name":"Spirituality enhancement","url":"https://psychonautwiki.org/wiki/Spirituality_enhancement"},{"name":"Existential self-realization","url":"https://psychonautwiki.org/wiki/Existential_self-realization"},{"name":"Muscle contractions","url":"https://psychonautwiki.org/wiki/Muscle_contractions"},{"name":"Increased sense of humor","url":"https://psychonautwiki.org/wiki/Increased_sense_of_humor"},{"name":"Machinescapes","url":"https://psychonautwiki.org/wiki/Machinescapes"},{"name":"Thought connectivity","url":"https://psychonautwiki.org/wiki/Thought_connectivity"},{"name":"Magnification","url":"https://psychonautwiki.org/wiki/Magnification"},{"name":"Changes in felt bodily form","url":"https://psychonautwiki.org/wiki/Changes_in_felt_bodily_form"},{"name":"Paranoia","url":"https://psychonautwiki.org/wiki/Paranoia"},{"name":"Environmental patterning","url":"https://psychonautwiki.org/wiki/Environmental_patterning"},{"name":"Dehydration","url":"https://psychonautwiki.org/wiki/Dehydration"},{"name":"Temperature regulation suppression","url":"https://psychonautwiki.org/wiki/Temperature_regulation_suppression"},{"name":"Increased bodily temperature","url":"https://psychonautwiki.org/wiki/Increased_bodily_temperature"},{"name":"8A Geometry - Perceived exposure to semantic concept network","url":"https://psychonautwiki.org/wiki/8A_Geometry_-_Perceived_exposure_to_semantic_concept_network"},{"name":"Frame rate enhancement","url":"https://psychonautwiki.org/wiki/Frame_rate_enhancement"},{"name":"Introspection","url":"https://psychonautwiki.org/wiki/Introspection"},{"name":"Empathy, affection and sociability enhancement","url":"https://psychonautwiki.org/wiki/Empathy,_affection_and_sociability_enhancement"},{"name":"Motivation enhancement","url":"https://psychonautwiki.org/wiki/Motivation_enhancement"}],"name":"LSD","roas":[{"bioavailability":{"max":71,"min":71},"dose":{"common":{"max":150,"min":75},"heavy":300,"light":{"max":75,"min":25},"strong":{"max":300,"min":150},"threshold":15,"units":"µg"},"duration":{"afterglow":{"max":48,"min":12,"units":"hours"},"comeup":{"max":90,"min":45,"units":"minutes"},"duration":null,"offset":{"max":5,"min":3,"units":"hours"},"onset":{"max":30,"min":15,"units":"minutes"},"peak":{"max":5,"min":3,"units":"hours"},"total":{"max":12,"min":8,"units":"hours"}},"name":"sublingual"}],"toxicity":["extremely low toxicity relative to dose"],"uncertainInteractions":[{"class":{"chemical":["Cannabinoid"],"psychoactive":["Psychedelics"]},"name":"Cannabis","toxicity":["extremely low toxicity"]},{"class":null,"name":"Substituted amphetamine","toxicity":null},{"class":{"chemical":["Tropane_alkaloids","Benzoic_acid_ester"],"psychoactive":["Stimulants"]},"name":"Cocaine","toxicity":["individuals have died from as little as 30 mg applied to mucous membranes, whereas addicts may tolerate up to 5 grams daily"]}],"unsafeInteractions":null}]}}));

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
rec
mergeDeepRec(d1, d2)
pending…
iter
mergeDeepIter(d1, d2)
pending…
iter no-array
mergeDeepIter2(d1, d2)
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 Comments