Permalink
Browse files

Add native functions to benchmarks where they exist (#1929)

* Add native functions to benchmarks where they exist

 - Added benchmarks for either (addresses #1913)
 - Removed isSet benchmarks as isSet has been removed from ramda
 - Changed indexOf to includes in the contains benchmark as includes is
semantically closer to contains than indexOf

* Remove mixed native/ramda and invalid either benchmarks. Rename native contains
  • Loading branch information...
1 parent d314846 commit 1871ceed0a4a25c2d0c624d5078837ff5cc8c3c4 @bjdixon bjdixon committed with buzzdecafe Oct 30, 2016
@@ -15,6 +15,9 @@ module.exports = {
},
'concatS1(s2)': function() {
concatS1(s2);
+ },
+ 'native concat': function() {
+ s1.concat(s2);
}
}
};
@@ -6,8 +6,8 @@ function randomLowerAlpha() {
return String.fromCharCode(97 + (Math.random() * 26) >>> 0);
}
-function nativeIndexOf(x, xs) {
- return xs.indexOf(x) >= 0;
+function nativeContains(x, xs) {
+ return xs.includes(x);
}
module.exports = {
@@ -16,8 +16,8 @@ module.exports = {
'contains(c, cs)': function() {
return contains(randomLowerAlpha(), alphabet);
},
- 'native indexOf': function() {
- return nativeIndexOf(randomLowerAlpha(), alphabet);
+ 'native contains': function() {
+ return nativeContains(randomLowerAlpha(), alphabet);
}
}
};
@@ -12,6 +12,10 @@ module.exports = {
'forEach(x2)(nums)': function() {
var result = [];
forEach(function(x) { result.push(x); })(nums);
+ },
+ 'native forEach': function() {
+ var result = [];
+ nums.forEach(function(x) { result.push(x); });
}
}
};
@@ -0,0 +1,28 @@
+var R = require('../..');
+
+var gt10 = x => x > 10;
+var even = x => x % 2 === 0;
+
+module.exports = {
+ name: 'either',
+ tests: {
+ 'either(gt10, even)(101)': function() {
+ R.either(gt10, even)(101);
+ },
+ 'either(gt10)(even)(101)': function() {
+ R.either(gt10)(even)(101);
+ },
+ 'either(gt10, even)(8)': function() {
+ R.either(gt10, even)(8);
+ },
+ 'either(gt10)(even)(8)': function() {
+ R.either(gt10)(even)(8);
+ },
+ 'native gt10(101) || even(101)': function() {
+ gt10(101) || even(101);
+ },
+ 'native gt10(8) || even(8)': function() {
+ gt10(8) || even(8);
+ }
+ }
+};
@@ -15,6 +15,9 @@ module.exports = {
},
'filterEven(nums)': function() {
filterEven(nums);
+ },
+ 'native filter': function() {
+ nums.filter(isEven);
}
}
};
@@ -15,6 +15,9 @@ module.exports = {
},
'findZero(nums)': function() {
findZero(nums);
+ },
+ 'native find': function() {
+ nums.find(isZero);
}
}
};
@@ -15,6 +15,9 @@ module.exports = {
},
'findIndexZero(nums)': function() {
findIndexZero(nums);
+ },
+ 'native findIndex': function() {
+ nums.findIndex(isZero);
}
}
};
@@ -14,6 +14,9 @@ module.exports = {
},
'idxOf23(nums)': function() {
idxOf23(nums);
+ },
+ 'native indexOf': function() {
+ nums.indexOf(23);
}
}
};
@@ -1,24 +0,0 @@
-var isSet = require('../..').isSet;
-
-var unsortedBag = [8, 2, 85, 2, 34, 3, 23, 247, 57, 8, 0, 6, 5, 46, 54, 643];
-var unsortedSet = [8, 2, 85, 34, 3, 23, 247, 57, 8, 0, 6, 5, 46, 54, 643];
-var sortedSet = unsortedSet.sort();
-var sortedBag = unsortedBag.sort();
-
-module.exports = {
- name: 'isSet',
- tests: {
- 'isSet(unsortedBag)': function() {
- isSet(unsortedBag);
- },
- 'isSet(unsortedSet)': function() {
- isSet(unsortedSet);
- },
- 'isSet(sortedBag)': function() {
- isSet(sortedBag);
- },
- 'isSet(sortedSet)': function() {
- isSet(sortedSet);
- }
- }
-};
@@ -15,6 +15,9 @@ module.exports = {
},
'mapSq(nums)': function() {
mapSq(nums);
+ },
+ 'native map': function() {
+ nums.map(sq);
}
}
};
@@ -14,6 +14,9 @@ module.exports = {
},
'reduceAdd(nums)': function() {
reduceAdd(nums);
+ },
+ 'native reduce': function() {
+ nums.reduce(add, 0);
}
}
};

0 comments on commit 1871cee

Please sign in to comment.