Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
a32131
(version: 0)
123123
Comparing performance of:
1 vs 2
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
1
function firstDup (s, r = undefined) { const haveSeen = [] s.split("").reverse().forEach(c => haveSeen.includes(c) ? r = c : haveSeen.push(c)) return r } firstDup('tweet') firstDup('Ode to Joy') firstDup('ode to joy') firstDup('bar') firstDup('123123') firstDup('!@#$!@#$') firstDup('!@#$!@#$!@#awe21312123l1k32l123kçl123jklçjeqwklj123lkçj12lk123jlçk231111111111111131jkl213kl14h12h531jk5jh13531hj5hj311j5h351h3lklç531hl531hl1ç35lhçk5klh531hç513hl531lhk315lh$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$')
2
const firstDup = s => s.split("").find((c, i) => s.slice(i+1).includes(c)) firstDup('tweet') firstDup('Ode to Joy') firstDup('ode to joy') firstDup('bar') firstDup('123123') firstDup('!@#$!@#$') firstDup('!@#$!@#$!@#awe21312123l1k32l123kçl123jklçjeqwklj123lkçj12lk123jlçk231111111111111131jkl213kl14h12h531jk5jh13531hj5hj311j5h351h3lklç531hl531hl1ç35lhçk5klh531hç513hl531lhk315lh$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$!@#$')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
1
2
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):
I'll break down the provided benchmark definition and test cases, explaining what's being tested, compared options, pros and cons, and other considerations. **Benchmark Definition** The benchmark definition consists of two JavaScript functions: 1. `firstDup(s, r = undefined)`: This function takes a string `s` and an optional return variable `r`. It splits the string into individual characters, reverses the order, and checks if each character is already present in the reversed string. If it finds a duplicate character, it returns that character. 2. `const firstDup = s => s.split(\"\").find((c, i) => s.slice(i+1).includes(c))`: This is an arrow function equivalent of the previous one. It uses the `find()` method to search for the first duplicate character in the string. **Test Cases** The test cases are arrays of JavaScript functions that call the `firstDup` function with different strings: ```javascript function firstDup(s, r = undefined) { const haveSeen = []; s.split("").reverse().forEach(c => haveSeen.includes(c) ? r = c : haveSeen.push(c)); return r; } console.log(firstDup("tweet")); firstDup("Ode to Joy"); firstDup("ode to joy"); firstDup("bar"); firstDup("123123"); firstDup("!@#$!@#$"); ``` and ```javascript const firstDup = s => s.split("").find((c, i) => s.slice(i+1).includes(c)); console.log(firstDup("tweet")); firstDup("Ode to Joy"); firstDup("ode to joy"); firstDup("bar"); firstDup("123123"); firstDup("!@#$!@#$"); ``` **Options Compared** In the first test case, two options are compared: - The first function uses a `forEach` loop and iterates over each character in reverse order. - The second function uses the `find()` method to search for the first duplicate character. The first option is more explicit but might be slower due to the additional overhead of reversing the string and checking if each character is already present. The second option, being a built-in method of arrays in JavaScript, is likely faster but less readable. In the second test case, the two options are identical: both use arrow functions with `find()` methods. This comparison is not as relevant since both functions produce the same output and have similar performance characteristics. **Performance Comparison** The latest benchmark result shows that Chrome 105 on Windows Desktop executes the first function at a rate of approximately 712,843 executions per second, while the second function is executed at about 27,181 executions per second. This suggests that the first function, which iterates over each character in reverse order and checks for duplicates using `includes()`, is significantly slower than the second function, which uses the `find()` method to search for the first duplicate character. **Pros and Cons** The pros of the first function are: * More explicit code * Less reliance on built-in methods However, this comes at a cost: * Potential performance overhead due to reversing the string and checking for duplicates using `includes()` The cons of the second function are: * Less readable due to relying on built-in methods * Performance characteristics might not be as clear-cut as they appear with `find()`
Related benchmarks:
ToKebabCase3
Normalize digits
Number Conversion Speed
trailingZeroes removal
toBase62String
Comments
Confirm delete:
Do you really want to delete benchmark?