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
let sampleText = 'ForloopingthroughthecharMapobject,weinitializetwovariablesatthebeginning.'
function maxRecurringCharIteration(text) {
let charMap = {}
let maxCharValue = 0
let maxChar = ''
for (let char of text) {
if (charMap.hasOwnProperty(char)) {
charMap[char]++
} else {
charMap[char] = 1
}
}
for (let char in charMap) {
if (charMap[char] > maxCharValue) {
maxCharValue = charMap[char]
maxChar = char
}
}
return maxChar
}
function maxRecurringCharArrays(text) {
let charMap = {}
let charArray =[]
let vaulesArray = []
let maxCharValue = 0
for (let char of text) {
if (charMap.hasOwnProperty(char)) {
charMap[char]++
} else {
charMap[char] = 1
}
}
charArray = Object.keys(charMap)
vaulesArray = Object.values(charMap)
maxCharValue = Math.max(...vaulesArray)
return charArray[vaulesArray.indexOf(maxCharValue)]
}
Ready to run.
Test | Ops/sec | |
---|---|---|
For...in Iteration |
| ready |
Forming Arrays from a character map |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.