iterative zip vs functional zip

Benchmark created on


Preparation HTML

<script>
  function iter_zip() { var i, j, len, result, lists
    lists  = [].slice.call(arguments)
    len    = lists.length
    result = []
          
    for (i = 0; i < len; ++i) {
      result[i] = []
      for (j = 0; j < len; ++j)  result[i].push(lists[j][i]) }
  
    return result
  }
  
  function zip(list) { var others
    others = [].slice.call(arguments, 1)
  
    return list.reduce(function(result, value, idx) { var values
      values = others.map(function(list){ return list[idx] })
      values.unshift(value)
      result.push(values)
      return result }, [])        
  }
  
  var arr1 = ['a','b','c','d','e','f']
    , arr2 = [ 1,  2,  3,  4,  5,  6 ]
    , arr3 = ['foo', 'bar', 'baz', 'foobar']
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
iterative zip
iter_zip(arr1, arr2, arr3)
ready
functional zip
zip(arr1, arr2, arr3)
ready

Revisions

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