Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Pagination 11123f
(version: 0)
Comparing performance of:
new vs old
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
new
const offsetSize = 2; const offsetsSize = offsetSize * 2; const viewSize = offsetsSize + 1; const getPages = (current, pagesCount) => { const normalizedViewSize = viewSize < pagesCount ? viewSize : pagesCount; const viewEnd = current + offsetSize; const normalizedViewEnd = viewEnd < pagesCount ? viewEnd : pagesCount; const viewStart = normalizedViewEnd - normalizedViewSize + 1; const normalizedViewStart = viewStart > 0 ? viewStart : 1; const startPage = (current >= offsetsSize && [1]) || []; const startDots = (current > offsetsSize && ['dots']) || []; const pages = [...Array(normalizedViewSize)].map((_, i) => normalizedViewStart + i); const endDots = (viewEnd < pagesCount && ['dots']) || []; const endPage = (viewEnd <= pagesCount && [pagesCount]) || []; return [...startPage, ...startDots, ...pages, ...endDots, ...endPage]; }; getPages(1, 200);
old
const getPages = (current, pagesCount) => { let items = []; let start = current - 3; let end = current + 3; if (current === 5) items = [1]; if (current > 5) items = [1, 'dots']; if (start <= 1) start = 1; if (end > pagesCount) end = pagesCount; for (let i = start; i <= end; i++) { items.push(i); } if (end + 1 < pagesCount) { items = [...items, 'dots', pagesCount]; } else if (end < pagesCount) { items = [...items, pagesCount]; } return items; }; getPages(1, 200);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
new
old
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):
The provided benchmark measures the performance of two different implementations of a pagination function in JavaScript, which is used to generate an array of page numbers for a given set of pages. **Benchmark Definition** The benchmark definition is simply a string that contains the code of the `getPages` function, which takes two arguments: `current` and `pagesCount`. The function returns an array of page numbers. In this case, there are two implementations: 1. **New implementation**: This implementation uses a more modern and concise syntax to calculate the start and end pages. 2. **Old implementation**: This implementation uses a more traditional and verbose approach to calculate the start and end pages. **Options Compared** The benchmark compares the performance of these two different implementations: * **Algorithmic complexity**: The new implementation has a more efficient algorithm for calculating the start and end pages, which reduces the number of iterations required. * **Syntax and structure**: The old implementation uses a more traditional syntax with multiple `if` statements, while the new implementation uses a more concise syntax with conditional expressions. **Pros and Cons** **New Implementation:** Pros: * More efficient algorithm * Concise syntax * Easier to maintain and update Cons: * May be less readable for those familiar with traditional syntax **Old Implementation:** Pros: * More readable due to traditional syntax * May be more familiar to those with experience in older JavaScript versions Cons: * Less efficient algorithm * Verbose syntax * More difficult to maintain and update **Library Usage** There are no libraries explicitly used in the benchmark code. **Special JS Features or Syntax** The new implementation uses: * **Conditional expressions**: A concise way to express conditional logic using the `?:` operator. * **Spread operator**: Used to create a new array by spreading elements from an existing array. * **Template literals**: Not actually used, but it's worth mentioning that template literals are available in modern JavaScript. **Other Considerations** When choosing between these two implementations, consider the following: * Performance: If performance is critical, the new implementation may be a better choice due to its more efficient algorithm. * Code readability and maintainability: The old implementation may be easier to read and understand for those familiar with traditional syntax. * Future-proofing: The new implementation uses modern JavaScript features that are likely to remain in use for future versions. **Alternatives** Other alternatives to implement a pagination function could include: * Using an existing library, such as `lodash`, which provides a `paginate` function. * Implementing a custom pagination algorithm using a different approach, such as using a queue data structure. * Using a more high-level programming paradigm, such as functional programming, to simplify the implementation.
Related benchmarks:
Large number product of x consecutive digits
bignumber.js vs. big.js vs. decimal.js 2022 ver. (random)
bignumber.js vs. big.js vs. decimal.js 2022 ver. (random) (no toFixed)
Verifica CNPJ
test ipsum
Comments
Confirm delete:
Do you really want to delete benchmark?