jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
/*Generate a list of all Combinations*/
function getCombinations(list){
var combinations = []; //All combinations
var combination = []; //Single combination
var quantity = (1 << list.length);
for (var i = 0; i < quantity ; i++){
combination = [];
for (var j=0;j<list.length;j++) {
if ((i & (1 << j))){
combination.push(list[j]);
}
}
if (combination.length !== 0) {
combinations.push(combination);
}
}
return combinations;
}
/*Generate a product from a list of numbers*/
function listProduct(list){
var product=1;
for (var i=0;i<list.length;i++){
product *=list[i];
}
return product;
}
/*Return the arithmetic sum*/
function arithmeticSum (a, n){
return (1/2)*n*(a+a*n);
}
/*Generate the arithmetic sum of a series based on a multiple*/
function arithmeticSumFromSeriesMultiple (series, multiple){
var a = multiple;
var n = Math.floor(series/multiple);
return arithmeticSum(a, n);
}
function sumMultiples(range, multiples){
var sum= 0;
var subsetSums = [];
var multiplesCombination=getCombinations(multiples);
for (var i=0;i<multiplesCombination.length;i++){
//Generate product from combinations of multiples
//and
//Find individual sums of all combinations.
subsetSums.push(
arithmeticSumFromSeriesMultiple(
range,
listProduct(multiplesCombination[i])
)
);
}
for (var i=1; i< subsetSums.length + 1;i++){
//Check if i is an even base 2.
if ((i & (i - 1)) == 0){
console.log(">" + subsetSums[i-1])
sum += subsetSums[i-1];
} else {
console.log("<" + subsetSums[i-1])
sum -= subsetSums[i-1];
}
}
return sum;
}
function sumMultiples2(n, multiples){
var sum= 0;
var isMultiple = function(n, multiple){
return ((n % multiple) === 0);
};
var commonMultiples = function (n,multiples){
var isCommon = false;
for (var i=0;i<multiples.length;i++){
isCommon = (isCommon || isMultiple(n, multiples[i]));
}
return isCommon;
};
for (var i=1;i<n;i++) {
if (commonMultiples (i,multiples)) {
sum += i;
}
}
return sum;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
nomath small |
| ready |
math small |
| ready |
nomath big |
| ready |
math big |
| ready |
math huge |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.