Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Card Art Name
(version: 0)
Old vs new implementation
Comparing performance of:
Old vs New
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
Old
const parseConsumerDisplayName = (firstName, middleName, lastName) => { const fullName = [lastName, firstName, middleName] .filter(Boolean) .join(' ') .substr(0, 26); const givenNames = fullName.substring(lastName.length, fullName.length); return [givenNames, lastName].join(' '); }; parseConsumerDisplayName('Test', 'M', 'Name'); parseConsumerDisplayName('ReallyReallyLongFirstName', 'M', 'AbsurdlyLongLastName');
New
const parseConsumerDisplayName = (firstName, middleName, lastName) => { const lastNameLength = lastName.length; const givenNames = [firstName, middleName].filter(Boolean).join(' ').substr(0, 26-lastNameLength); return [givenNames, lastName].join(' '); }; parseConsumerDisplayName('Test', 'M', 'Name'); parseConsumerDisplayName('ReallyReallyLongFirstName', 'M', 'AbsurdlyLongLastName');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Old
New
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):
**Overview of the Benchmark** The provided JSON represents a JavaScript microbenchmark created on MeasureThat.net. The benchmark tests two different implementations of a function `parseConsumerDisplayName`, which takes three string parameters: `firstName`, `middleName`, and `lastName`. The goal is to determine which implementation is faster. **Test Cases** There are only two test cases: 1. **Old**: This implementation uses the original code provided in the benchmark definition, with no modifications. ```javascript const parseConsumerDisplayName = (firstName, middleName, lastName) => { const fullName = [lastName, firstName, middleName] .filter(Boolean) .join(' ') .substr(0, 26); const givenNames = fullName.substring(lastName.length, fullName.length); return [givenNames, lastName].join(' '); }; ``` 2. **New**: This implementation is a modified version of the original code, with changes to improve performance. ```javascript const parseConsumerDisplayName = (firstName, middleName, lastName) => { const lastNameLength = lastName.length; const givenNames = [firstName, middleName] .filter(Boolean) .join(' ') .substr(0, 26 - lastNameLength); return [givenNames, lastName].join(' '); }; ``` **Comparison of Options** The two implementations differ in the way they calculate `givenNames`. The **Old** implementation uses a substring operation to extract `givenNames`, while the **New** implementation uses a different approach with a subtraction-based optimization. Pros and Cons: * **Old**: + Pros: Simple and easy to understand. + Cons: May be slower due to the substring operation. * **New**: + Pros: Optimized for performance, potentially faster than the **Old** implementation. + Cons: More complex code, which may make it harder to understand. **Other Considerations** The benchmark uses a JavaScript engine (Chrome 85) and runs on a desktop platform with macOS 10.15.6. The `parseConsumerDisplayName` function is designed to extract the first name from a full name, taking into account middle names. **Libraries and Special Features** There are no libraries used in this benchmark. However, it's worth noting that some JavaScript engines or browsers may have specific optimizations or features that could affect the performance of this code (e.g., `const` propagation or `String.prototype.substr()` optimization). **Alternatives** If you wanted to write a similar benchmark, you could consider using other test frameworks like JSMbench or Benchmark.js. MeasureThat.net is specifically designed for JavaScript microbenchmarks, and its UI provides a convenient way to run and compare multiple tests. In terms of alternatives for writing the `parseConsumerDisplayName` function itself, you could explore other approaches, such as: * Using a more efficient algorithm for extracting first names from full names. * Implementing a caching mechanism to store intermediate results. * Utilizing parallel processing or concurrency to improve performance.
Related benchmarks:
Date.now(); vs new Date()
Uint16Array.from() vs new Uint16Array()
Comparing Uint16Array.from() vs new Uint16Array()
Array.from({ length: n }) vs new Array(n)
Array.from() vs new A
Comments
Confirm delete:
Do you really want to delete benchmark?