Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
exercism-pangram
(version: 0)
Test different pangram evaluations
Comparing performance of:
Loop over characters, check if in input Set vs Flip object keys vs Compare two sets (generate letterSet) vs Compare two sets (static letterSet)
Created:
7 years ago
by:
Guest
Jump to the latest result
Tests:
Loop over characters, check if in input Set
function isPangram(str) { const s = new Set(str.toLowerCase()) let a = 97 for (let i = 0; i < 26; i++) { if (!s.has(String.fromCharCode(a + i))) return false } return true } console.log(isPangram('the quick brown fox jumps over the lazy dog'))
Flip object keys
function isPangram (str) { let a = 97 let seen = {} for (let i = 0; i < 26; i++) { seen[String.fromCharCode(a + i)] = false } str.toLowerCase().split('').map(char => (seen[char] = true)) return Object.values(seen).every(val => val) } console.log(isPangram('the quick brown fox jumps over the lazy dog'))
Compare two sets (generate letterSet)
function isPangram (str) { let a = 97 let letterSet = new Set() for (let i = 0; i < 26; i++) { letterSet.add(String.fromCharCode(a + i)) } const inputSet = new Set(str.replace(/[^a-zA-Z]/g, '').toLowerCase()) return letterSet.size === inputSet.size } console.log(isPangram('the quick brown fox jumps over the lazy dog'))
Compare two sets (static letterSet)
function isPangram (str) { let letterSet = new Set('abcdefghijklmnopqrstuvwxyz') const inputSet = new Set(str.replace(/[^a-zA-Z]/g, '').toLowerCase()) return letterSet.size === inputSet.size } console.log(isPangram('the quick brown fox jumps over the lazy dog'))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Loop over characters, check if in input Set
Flip object keys
Compare two sets (generate letterSet)
Compare two sets (static letterSet)
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!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring JavaScript performance is a complex task, and MeasureThat.net provides a great platform for doing so. **Benchmark Overview** The provided benchmark tests the efficiency of different approaches to determine whether a given string is a pangram (a sentence that uses all the letters of the alphabet at least once). The test cases use various methods to generate or manipulate sets of characters, which are then compared to determine if they match the alphabet set. **Approaches Compared** There are four test cases: 1. **Loop over characters, check if in input Set**: This approach iterates over each character in the alphabet and checks if it exists in the input string's set. It uses a simple `Set` data structure. 2. **Flip object keys**: This approach creates an object with alphabet characters as keys and initializes their values to `false`. It then maps each character of the input string to the corresponding value in the object, effectively flipping the keys. Finally, it checks if all values are `true`. 3. **Compare two sets (generate letterSet)**: This approach generates a set of alphabet characters using the ASCII values of 'a' to 'z'. It then compares this set with the input string's set to determine if they match. 4. **Compare two sets (static letterSet)**: Similar to the previous approach, but the alphabet set is defined statically and not generated dynamically. **Pros and Cons** Here are some pros and cons for each approach: * **Loop over characters, check if in input Set**: Pros - simple and straightforward implementation. Cons - may be slower due to the iteration overhead. * **Flip object keys**: Pros - avoids the need for explicit set operations or alphabet generation. Cons - may have higher memory usage due to the object creation. * **Compare two sets (generate letterSet)**: Pros - generates a fixed, pre-computed alphabet set, which can reduce execution time. Cons - requires more memory allocation and string manipulation. * **Compare two sets (static letterSet)**: Similar pros and cons as above. **Library and Special JS Features** No libraries are used in these test cases, but JavaScript's built-in `Set` data structure is utilized to efficiently store and compare character sets. **Other Considerations** When choosing an approach for a performance benchmark like this one, consider the following factors: * **Memory usage**: Some approaches may consume more memory due to object creation or set operations. * **Algorithmic complexity**: More complex algorithms might have higher execution times due to additional iterations or function calls. * **Cache efficiency**: Accessing frequently used data in cache can significantly reduce execution time. **Alternatives** For alternative approaches, you could consider: * Using a more efficient data structure like a trie (prefix tree) for alphabet character lookup. * Utilizing SIMD instructions to compare sets of characters in parallel. * Employing a more advanced algorithm that leverages JavaScript's performance features, such as `Promise.all()` or Web Workers. Keep in mind that the choice of approach ultimately depends on your specific use case and requirements. MeasureThat.net provides a great platform for testing different approaches and finding the most efficient solution for your problem.
Related benchmarks:
comp test
slice vs substr vs substring (with end index & large string)
bench hubble .startsWith() vs .test() vs .match() vs .indexOf()
slice vs substring (long string)
String.prototype.split vs String.prototype.match for word count
Comments
Confirm delete:
Do you really want to delete benchmark?