slice+reduce_vs_from

JavaScript performance comparison

Test case created by augurone

Preparation code

<a href="adobe.com/page0">0</a><a href="adobe.com/page1">1</a><a href="adobe.com/page2">2</a><a href="adobe.com/page3">3</a><a href="adobe.com/page4">4</a><a href="adobe.com/page5">5</a><a href="adobe.com/page6">6</a><a href="adobe.com/page7">7</a><a href="adobe.com/page8">8</a><a href="adobe.com/page9">9</a><a href="adobe.com/page10">10</a><a href="adobe.com/page11">11</a><a href="adobe.com/page12">12</a><a href="adobe.com/page13">13</a><a href="adobe.com/page14">14</a><a href="adobe.com/page15">15</a><a href="adobe.com/page16">16</a><a href="adobe.com/page17">17</a><a href="adobe.com/page18">18</a><a href="adobe.com/page19">19</a><a href="adobe.com/page20">20</a><a href="adobe.com/page21">21</a><a href="adobe.com/page22">22</a><a href="adobe.com/page23">23</a><a href="adobe.com/page24">24</a><a href="adobe.com/page25">25</a><a href="adobe.com/page26">26</a><a href="adobe.com/page27">27</a><a href="adobe.com/page28">28</a><a href="adobe.com/page29">29</a><a href="adobe.com/page30">30</a><a href="adobe.com/page31">31</a><a href="adobe.com/page32">32</a><a href="adobe.com/page33">33</a><a href="adobe.com/page34">34</a><a href="adobe.com/page35">35</a><a href="adobe.com/page36">36</a><a href="adobe.com/page37">37</a><a href="adobe.com/page38">38</a><a href="adobe.com/page39">39</a><a href="adobe.com/page40">40</a><a href="adobe.com/page41">41</a><a href="adobe.com/page42">42</a><a href="adobe.com/page43">43</a><a href="adobe.com/page44">44</a><a href="adobe.com/page45">45</a><a href="adobe.com/page46">46</a><a href="adobe.com/page47">47</a><a href="adobe.com/page48">48</a><a href="adobe.com/page49">49</a><a href="adobe.com/page50">50</a><a href="adobe.com/page51">51</a><a href="adobe.com/page52">52</a><a href="adobe.com/page53">53</a><a href="adobe.com/page54">54</a><a href="adobe.com/page55">55</a><a href="adobe.com/page56">56</a><a href="adobe.com/page57">57</a><a href="adobe.com/page58">58</a><a href="adobe.com/page59">59</a><a href="adobe.com/page60">60</a><a href="adobe.com/page61">61</a><a href="adobe.com/page62">62</a><a href="adobe.com/page63">63</a><a href="adobe.com/page64">64</a><a href="adobe.com/page65">65</a><a href="adobe.com/page66">66</a><a href="adobe.com/page67">67</a><a href="adobe.com/page68">68</a><a href="adobe.com/page69">69</a><a href="adobe.com/page70">70</a><a href="adobe.com/page71">71</a><a href="adobe.com/page72">72</a><a href="adobe.com/page73">73</a><a href="adobe.com/page74">74</a><a href="adobe.com/page75">75</a><a href="adobe.com/page76">76</a><a href="adobe.com/page77">77</a><a href="adobe.com/page78">78</a><a href="adobe.com/page79">79</a><a href="adobe.com/page80">80</a><a href="adobe.com/page81">81</a><a href="adobe.com/page82">82</a><a href="adobe.com/page83">83</a><a href="adobe.com/page84">84</a><a href="adobe.com/page85">85</a><a href="adobe.com/page86">86</a><a href="adobe.com/page87">87</a><a href="adobe.com/page88">88</a><a href="adobe.com/page89">89</a><a href="adobe.com/page90">90</a><a href="adobe.com/page91">91</a><a href="adobe.com/page92">92</a><a href="adobe.com/page93">93</a><a href="adobe.com/page94">94</a><a href="adobe.com/page95">95</a><a href="adobe.com/page96">96</a><a href="adobe.com/page97">97</a><a href="adobe.com/page98">98</a><a href="adobe.com/page99">99</a>
      
<script>
Benchmark.prototype.setup = function() {
  const allAs = document.querySelectorAll('a');

};
</script>

Preparation code output

<a href="adobe.com/page0">0</a><a href="adobe.com/page1">1</a><a href="adobe.com/page2">2</a><a href="adobe.com/page3">3</a><a href="adobe.com/page4">4</a><a href="adobe.com/page5">5</a><a href="adobe.com/page6">6</a><a href="adobe.com/page7">7</a><a href="adobe.com/page8">8</a><a href="adobe.com/page9">9</a><a href="adobe.com/page10">10</a><a href="adobe.com/page11">11</a><a href="adobe.com/page12">12</a><a href="adobe.com/page13">13</a><a href="adobe.com/page14">14</a><a href="adobe.com/page15">15</a><a href="adobe.com/page16">16</a><a href="adobe.com/page17">17</a><a href="adobe.com/page18">18</a><a href="adobe.com/page19">19</a><a href="adobe.com/page20">20</a><a href="adobe.com/page21">21</a><a href="adobe.com/page22">22</a><a href="adobe.com/page23">23</a><a href="adobe.com/page24">24</a><a href="adobe.com/page25">25</a><a href="adobe.com/page26">26</a><a href="adobe.com/page27">27</a><a href="adobe.com/page28">28</a><a href="adobe.com/page29">29</a><a href="adobe.com/page30">30</a><a href="adobe.com/page31">31</a><a href="adobe.com/page32">32</a><a href="adobe.com/page33">33</a><a href="adobe.com/page34">34</a><a href="adobe.com/page35">35</a><a href="adobe.com/page36">36</a><a href="adobe.com/page37">37</a><a href="adobe.com/page38">38</a><a href="adobe.com/page39">39</a><a href="adobe.com/page40">40</a><a href="adobe.com/page41">41</a><a href="adobe.com/page42">42</a><a href="adobe.com/page43">43</a><a href="adobe.com/page44">44</a><a href="adobe.com/page45">45</a><a href="adobe.com/page46">46</a><a href="adobe.com/page47">47</a><a href="adobe.com/page48">48</a><a href="adobe.com/page49">49</a><a href="adobe.com/page50">50</a><a href="adobe.com/page51">51</a><a href="adobe.com/page52">52</a><a href="adobe.com/page53">53</a><a href="adobe.com/page54">54</a><a href="adobe.com/page55">55</a><a href="adobe.com/page56">56</a><a href="adobe.com/page57">57</a><a href="adobe.com/page58">58</a><a href="adobe.com/page59">59</a><a href="adobe.com/page60">60</a><a href="adobe.com/page61">61</a><a href="adobe.com/page62">62</a><a href="adobe.com/page63">63</a><a href="adobe.com/page64">64</a><a href="adobe.com/page65">65</a><a href="adobe.com/page66">66</a><a href="adobe.com/page67">67</a><a href="adobe.com/page68">68</a><a href="adobe.com/page69">69</a><a href="adobe.com/page70">70</a><a href="adobe.com/page71">71</a><a href="adobe.com/page72">72</a><a href="adobe.com/page73">73</a><a href="adobe.com/page74">74</a><a href="adobe.com/page75">75</a><a href="adobe.com/page76">76</a><a href="adobe.com/page77">77</a><a href="adobe.com/page78">78</a><a href="adobe.com/page79">79</a><a href="adobe.com/page80">80</a><a href="adobe.com/page81">81</a><a href="adobe.com/page82">82</a><a href="adobe.com/page83">83</a><a href="adobe.com/page84">84</a><a href="adobe.com/page85">85</a><a href="adobe.com/page86">86</a><a href="adobe.com/page87">87</a><a href="adobe.com/page88">88</a><a href="adobe.com/page89">89</a><a href="adobe.com/page90">90</a><a href="adobe.com/page91">91</a><a href="adobe.com/page92">92</a><a href="adobe.com/page93">93</a><a href="adobe.com/page94">94</a><a href="adobe.com/page95">95</a><a href="adobe.com/page96">96</a><a href="adobe.com/page97">97</a><a href="adobe.com/page98">98</a><a href="adobe.com/page99">99</a>

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
Slice+Reduce
Array.prototype.slice.call(allAs).reduce((acc, a) => {
  const { href } = a;
  if (/9/.test(href)) {
    acc.push(href);
  }
  return acc;
}, []);
pending…
From
Array.from(allAs, ({ href = '' }) => {
  if (/9/.test(href)) {
    return href;
  }
  return '';
});
pending…
Spread + Reduce
[...allAs].reduce((acc, a) => {
  const { href } = a;
  if (/9/.test(href)) {
    acc.push(href);
  }
  return acc;
}, []);
pending…
Map
[...allAs].map((a) => {
  const { href } = a;
  if (/9/.test(href)) {
    return href;
   }
   return '';
});
pending…
forEach
const arr = [];
[...allAs].forEach((a) => {
  const { href } = a;
  if (/9/.test(href)) {
    arr.push(href);
  }
});
pending…
for
const arr = [];
for (i=0; Boolean(a = allAs[i]); i++) {
  const href = a.href;
  if (/9/.test(href)) {
    arr.push(href);
  }
}
pending…
from + reduce
Array.from(allAs).reduce((acc, a) => {
  const { href } = a;
  if (/9/.test(href)) {
    acc.push(href);
  }
  return acc;
}, []);
pending…

Compare results of other browsers

Revisions

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

0 Comments

0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899