mapreduce874923743kes

JavaScript performance comparison

Test case created by LuneXsg

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const data = 
    [ [ { value: 5, suit: 's' },
        { value: 4, suit: 's' },
        { value: 6, suit: 'c' },
        { value: 11, suit: 'd' },
        { value: 12, suit: 'c' } ],
      [ { value: 9, suit: 'd' },
        { value: 12, suit: 'h' },
        { value: 8, suit: 'c' },
        { value: 12, suit: 's' },
        { value: 2, suit: 's' } ],
      [ { value: 4, suit: 'h' },
        { value: 6, suit: 's' },
        { value: 10, suit: 'c' },
        { value: 3, suit: 'd' },
        { value: 7, suit: 'd' } ] ]

};
</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
Destructuring assignment
data.map(item => item.reduce(({ values, suits }, { value, suit }) => ({
  values: [...values, value],
  suits: [...suits, suit]
}), { values: [], suits: [] }))
pending…
Funtional
const map = f => xs => xs.map(f)

const reduce = f => y => xs => xs.reduce(f, y)

const handAppendCard = ({values, suits}, {value, suit}) => ({
  values: [...values, value],
  suits: [...suits, suit]
})

const makeHands =
  map (reduce (handAppendCard) ({values:[], suits:[]}))

makeHands (data)
pending…
forEach
data.map(item => item.reduce((prev, curr) => {
  Object.keys(prev).forEach(key => prev[key].push(curr[key]));
  return prev;
}, { value: [], suit: [] }))
pending…
For Loop
data.map(item => item.reduce((prev, curr) => {
  const keys = Object.keys(prev);
  for(let i = 0; i < keys.length; i++) {
    const key = keys[i];
    prev[key].push(curr[key]);
  }
  return prev;
}, { value: [], suit: [] }))
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