Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Ramda flatten function VS Array.prototype.flat
Compare a Ramda flatten function with Array.prototype.flat
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:122.0) Gecko/20100101 Firefox/122.0
Browser:
Firefox 122
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Ramda Flatten Function
275295.2 Ops/sec
Array.prototype.flat
1116435.2 Ops/sec
Script Preparation code:
function _isString(x) { return Object.prototype.toString.call(x) === '[object String]'; } function _isPlaceholder(a) { return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; } function _curry1(fn) { return function f1(a) { if (arguments.length === 0 || _isPlaceholder(a)) { return f1; } else { return fn.apply(this, arguments); } }; } var _isArrayLike = _curry1(function isArrayLike(x) { if (Array.isArray(x)) { return true; } if (!x) { return false; } if (typeof x !== 'object') { return false; } if (_isString(x)) { return false; } if (x.length === 0) { return true; } if (x.length > 0) { return x.hasOwnProperty(0) && x.hasOwnProperty(x.length - 1); } return false; }); function _makeFlat(recursive) { return function flatt(list) { var value, jlen, j; var result = []; var idx = 0; var ilen = list.length; while (idx < ilen) { if (_isArrayLike(list[idx])) { value = recursive ? flatt(list[idx]) : list[idx]; j = 0; jlen = value.length; while (j < jlen) { result[result.length] = value[j]; j += 1; } } else { result[result.length] = list[idx]; } idx += 1; } return result; } }; var flatten = _curry1(_makeFlat(true));
Tests:
Ramda Flatten Function
var params = [1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12], [1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11, [1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]], 12]]]]]]]; var other = flatten([1, 2, params]);
Array.prototype.flat
var params = [1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12], [1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11, [1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]], 12]]]]]]]; var other = [1, 2, params].flat(Infinity)