Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
example01
(version: 0)
Comparing performance of:
1 vs 2
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
1
function checkPart(part) { let reversed = part.split("").reverse().join(""); let isEqual = part === reversed; if (!isEqual) { const array = part.split(""); array.reduce((prev, curr, index) => { const result = array.slice(0, index - 1).join("") + array.slice(index).join(""); reversed = result.split("").reverse().join(""); if (result === reversed) isEqual = true; return curr; }); } return isEqual; } console.log(checkPart("uwu"));
2
function checkPart(part) { const textoOriginal = '' + part; const textoReverso = textoOriginal.split('').reverse().join(''); const resultado = textoOriginal.includes(textoReverso) || textoOriginal.split('').find((_, index) => { const arreglo = [...textoOriginal.split('')]; arreglo.splice(index, 1); const textoCortado = arreglo.join(''); return textoCortado.includes(arreglo.reverse().join('')); }); return resultado ? true : false; } console.log(checkPart("uwu"));
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:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 YaBrowser/24.7.0.0 Safari/537.36
Browser/OS:
Yandex Browser 24 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
1
171902.3 Ops/sec
2
193811.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Definition** The benchmark definition is a JSON object that provides basic information about the test. In this case, it's empty, which means there's no script preparation code or HTML preparation code provided. **Test Cases** There are two individual test cases: 1. **checkPart-1**: This function takes a string `part` as input and checks if it's equal to its reverse. If not, it uses the `Array.prototype.reduce()` method to find the longest prefix of the reversed string that is also a suffix of the original string. 2. **checkPart-2**: This function takes a string `part` as input and checks if it contains its reverse using the `includes()` method. It does this by splitting the string into an array, finding the index of the middle character, removing that character from the array, and checking if the resulting array still contains the reversed string. **Library Usage** Neither test case uses a library explicitly. However, both functions use built-in JavaScript methods like `split()`, `join()`, `reverse()`, `includes()`, and `find()`. **Special JS Features/Syntax** There are no special JavaScript features or syntax used in these test cases. They're straightforward function implementations using standard JavaScript constructs. **Benchmark Results** The latest benchmark results show two browsers (Yandex Browser 24 and an unspecified Chrome version) executing the tests at different rates: * **checkPart-1**: 193811.75 executions per second * **checkPart-2**: 171902.265625 executions per second These results suggest that `checkPart-1` is faster than `checkPart-2`, likely due to its more efficient use of the `Array.prototype.reduce()` method. **Other Considerations** When comparing these two test cases, consider the following: * **Efficiency**: `checkPart-1` is generally faster due to its optimized approach using `Array.prototype.reduce()`. * **Readability**: Both functions are relatively straightforward and easy to understand. * **Test Suite Quality**: To improve the quality of this test suite, you could add more test cases with different inputs or edge cases. **Alternatives** If you're interested in benchmarking similar JavaScript functions, consider using other tools like: 1. **Benchmark.js**: A popular benchmarking library for Node.js and browsers. 2. **jsperf.com**: A simple online tool for comparing the performance of JavaScript code snippets. 3. **jsbench.io**: Another online tool for benchmarking JavaScript code. Keep in mind that each tool has its strengths and weaknesses, so choose the one that best suits your specific use case and requirements.
Related benchmarks:
Updating objects w spread
Updating objects 2
for-in vs object.keys with for
for-in vs for..of object.keys
Compare switch vs dictionary complex 1000
Comments
Confirm delete:
Do you really want to delete benchmark?