I want to understand why these two equal benchmarks have different results on these two different platforms.
In the first one arr.filter(Boolean).join(" ")
is the fastest, in the second one is the slowest!
Why?
The code I'm using is this:
import classcat from "https://unpkg.com/classcat?module"
import clsx from "https://unpkg.com/clsx?module"
import objstr from "https://unpkg.com/obj-str?module"
const obj = {
one: true,
abcd: Math.random() <= 0.5,
efghijkl: Math.random() <= 0.5,
mnopqrstuvwxyz: Math.random() <= 0.5,
efghijklmnopqrstuvwxyz: Math.random() <= 0.5,
abcdefghijklmnopqrstuvwxyz: Math.random() <= 0.5,
abcd: Math.random() <= 0.5,
efghijkl: Math.random() <= 0.5,
mnopqrstuvwxyz: Math.random() <= 0.5,
efghijklmnopqrstuvwxyz: Math.random() <= 0.5,
abcdefghijklmnopqrstuvwxyz: Math.random() <= 0.5,
two: false,
three: true
}
const arr = [
true && "one",
Math.random() <= 0.5 && "abcd",
Math.random() <= 0.5 && "efghijkl",
Math.random() <= 0.5 && "mnopqrstuvwxyz",
Math.random() <= 0.5 && "efghijklmnopqrstuvwxyz",
Math.random() <= 0.5 && "abcdefghijklmnopqrstuvwxyz",
Math.random() <= 0.5 && "abcd",
Math.random() <= 0.5 && "efghijkl",
Math.random() <= 0.5 && "mnopqrstuvwxyz",
Math.random() <= 0.5 && "efghijklmnopqrstuvwxyz",
Math.random() <= 0.5 && "abcdefghijklmnopqrstuvwxyz",
false && "two",
true && "three",
]
classcat(arr)
classcat(obj)
clsx(arr)
clsx(obj)
objstr(obj)
arr.filter(Boolean).join(" ")