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
const purchasedProducts = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
const potentialRecommendations = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
// ================= //
function filterRecommendations(purchasedProducts, potentialRecommendations) {
return potentialRecommendations.filter(
(product) => !purchasedProducts.includes(product)
)
}
function filterRecommendationsFast(
purchasedProducts,
potentialRecommendations
) {
const purchasedProductsSet = new Set(purchasedProducts);
return potentialRecommendations.filter(
(productId) => !purchasedProductsSet.has(productId)
)
}
function filterRecommendationsFastest(
purchasedProducts,
potentialRecommendations
) {
const purchasedProductsObj = {}
for (let i = 0; i < purchasedProducts.length; i++) {
purchasedProductsObj[purchasedProducts[i]] = 0
}
return potentialRecommendations.filter(
(productId) => !(productId in purchasedProductsObj)
)
}
function filterRecommendationsFastest2(
purchasedProducts,
potentialRecommendations
) {
const result = []
for (let i = 0; i < potentialRecommendations.length; i++) {
const r = potentialRecommendations[i]
let found = false
for (let j = 0; j < purchasedProducts.length; j++) {
if (r == purchasedProducts[j]) found = true
}
if(!found)
result.push(r)
}
return result
}
function filterRecommendationsFastest3(
purchasedProducts,
potentialRecommendations
) {
const result = []
for (let i = 0; i < potentialRecommendations.length; i++) {
const r = potentialRecommendations[i]
let found = false
for (let j = 0; j < purchasedProducts.length; j++) {
if (r == purchasedProducts[j]){
found = true
break
}
}
if(!found)
result.push(r)
}
return result
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Slow |
| ready |
Fast |
| ready |
Fastest |
| ready |
Fastest 2 |
| ready |
Fastest 3 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.