Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Finite vs Known Multiples (High Limit)
(version: 0)
I'm a dog with a bone.
Comparing performance of:
Finite - Test all numbers within limit vs Multiples Only
Created:
6 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var limit = 10000; var total = 0;
Tests:
Finite - Test all numbers within limit
for (var i = 0; i < limit; i++) { if (i % 3 === 0 || i % 5 == 0) { total += i; } } console.log(total);
Multiples Only
var multiples = []; var i = 1; while (i * 3 < limit) { let m = i * 3; !multiples.includes(m) && multiples.push(m); i++; } i = 0; while (i * 5 < limit) { let m = i * 5; !multiples.includes(m) && multiples.push(m); i++; } console.log(multiples.reduce((a, b) => a + b, 0));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Finite - Test all numbers within limit
Multiples Only
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):
Let's break down the benchmark and its options. **Benchmark Definition** The provided benchmark is designed to test two different approaches to finding multiples of 3 or 5 within a given limit. The limit is set at 10,000. **Options Compared** There are two main options compared: 1. **Finite Loop**: This approach uses a traditional for loop to iterate through all numbers within the limit and checks if each number is a multiple of 3 or 5. 2. **Dynamic Array Approach**: This approach uses an array to store multiples of 3 and 5, and then sums them up. **Pros and Cons** ### Finite Loop Pros: * Simple to understand and implement * Directly calculates the sum of all desired numbers within the limit Cons: * May have performance issues due to the brute-force nature of the approach * Can be slow for large limits ### Dynamic Array Approach Pros: * More efficient than the finite loop approach, as it avoids redundant calculations * Takes advantage of JavaScript's array methods (e.g., includes, push) Cons: * More complex to implement and understand * Requires more memory to store the dynamic array **Library Used** None is explicitly mentioned in the provided benchmark definition. However, if we consider libraries like NumJS or Mathjs that can be used for numerical computations in JavaScript, they might provide a similar functionality. **Special JS Feature/Syntax** There isn't any special JavaScript feature or syntax being used in these benchmarks. They are standard JavaScript code examples. **Other Alternatives** Some alternative approaches to finding multiples of 3 or 5 could include: * Using a mathematical formula to directly calculate the sum of all desired numbers within the limit (e.g., using the formula for the sum of an arithmetic series) * Utilizing a more efficient algorithm, such as the Sieve of Eratosthenes to generate all prime numbers up to the limit and then filter for multiples of 3 or 5 * Using a just-in-time compiler like V8 (used by Chrome) to optimize performance
Related benchmarks:
toFixed vs toPrecision vs Math.round() vs Math.floorfast vs new Math.trunc vs numeraljs
JS BigInt multiply vs addition
BigInt to nu
parseInt vs Number BigInts
Javascript: reduce VS for with Math.max
Comments
Confirm delete:
Do you really want to delete benchmark?