Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
hamming distance again
(version: 0)
test of hamming distance JS implementation
Comparing performance of:
For In vs For Loop
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function hammingDistance(stringA, stringB) { if (stringA.length === stringB.length) { let count = 0 for (char in stringA){ if (stringA[char] !== stringB[char]) count++ } return count } else { return 'strings are not the same length' } } function hammingDistanceForLoop(stringA, stringB) { let result = 0 if (stringA.length == stringB.length) { for (let i = 0; i < stringA.length; i++) { if (stringA[i].toLowerCase() != stringB[i].toLowerCase()) { result++ } } return result } else { throw new Error('Strings do not have equal length') } }
Tests:
For In
hammingDistance('riverotter', 'roderofter')
For Loop
hammingDistanceForLoop('riverotter', 'roderofter')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
For In
For Loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
hamming distance.
large string comparison benchmark
Simple string compare vs MurmurHash on a large string
large string size comparison
Comments
Confirm delete:
Do you really want to delete benchmark?