Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
UOC Modul 1.2
(version: 0)
Comparing performance of:
David Lampon vs Switch case vs internet single line vs one single console log with internet version vs single console line with %15 vs Xavier Morell
Created:
7 years ago
by:
Guest
Jump to the latest result
Tests:
David Lampon
let result; for (let i = 0; i < 100; i++) { result = ""; if (i % 3 === 0) { result += "Fizz"; } if (i % 5 === 0) { result += "Buzz"; } else { result = i; } console.log(result); }
Switch case
for (let i = 0; i < 100; i++) { switch(0) { case i % 3 + i % 5: console.log("FizzBuzz"); break; case i % 3: console.log("Fizz"); break; case i % 5: console.log("Buzz"); break; default: console.log(i) } }
internet single line
for(let i=0;i<100;)console.log((++i%3?'':'fizz')+(i%5?'':'buzz')||i)
one single console log with internet version
console.log([...Array(100).keys()].map(i => (i%3?'':'fizz')+(i%5?'':'buzz')||i).join("\n"))
single console line with %15
console.log([...Array(100).keys()].map(i => (i % 15 ? (i % 3 ? ( i% 5 ? i : 'Buzz') : 'Fizz') : 'FizzBuz')).join("\n"))
Xavier Morell
for (let i = 0; i < 100; i++) { if (i % 3 === 0 && i % 5 === 0) console.log("FizzBuzz"); else if (i % 3 === 0) console.log("Fizz"); else if (i % 5 === 0) console.log("Buzz"); else console.log(i); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
David Lampon
Switch case
internet single line
one single console log with internet version
single console line with %15
Xavier Morell
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 provided benchmark and explain what's being tested. **Benchmark Definition** The benchmark is a series of JavaScript microbenchmarks that aim to measure the performance of different approaches for generating the FizzBuzz sequence. The sequence is generated by replacing multiples of 3 with "Fizz", multiples of 5 with "Buzz", and multiples of both with "FizzBuzz". **Options Compared** There are four main options compared in this benchmark: 1. **Single Line**: `for(let i=0;i<100;)console.log((++i%3?'':'fizz')+(i%5?'':'buzz')||i)` 2. **One Single Console Log with Internet Version**: `console.log([...Array(100).keys()].map(i => (i % 15 ? (i % 3 ? ( i% 5 ? i : 'Buzz') : 'Fizz') : 'FizzBuz')).join(\"\\n\"))` 3. **Traditional Loop**: `for (let i = 0; i < 100; i++) { ... }` (not used in this benchmark) 4. **Switch Case**: `switch(0) { case i % 3 + i % 5: console.log("FizzBuzz"); break; case i % 3: console.log("Fizz"); break; case i % 5: console.log("Buzz"); break; default: console.log(i); }` **Pros and Cons** 1. **Single Line**: This approach is concise and easy to read, but it may have performance issues due to the complexity of the expression. 2. **One Single Console Log with Internet Version**: This approach uses array mapping and join methods, which are efficient for large datasets. However, it may require more memory than other approaches. 3. **Traditional Loop**: This approach is straightforward and easy to understand, but it may be slower than other approaches due to the overhead of the loop control structures. 4. **Switch Case**: This approach can be less readable due to its complexity, but it can also be faster if the cases are well optimized. **Other Considerations** * The benchmark uses a fixed dataset (100 iterations) for all options, which may not accurately represent real-world scenarios where datasets can vary in size. * Some browsers (e.g., Chrome 69 on Mac OS X 10.13.2) have significantly faster execution times than others, which may be influenced by factors like hardware and software optimization. **Library Usage** None of the benchmark options explicitly use any JavaScript libraries or frameworks. However, some approaches may rely on built-in functions or methods that are provided by modern browsers (e.g., `Array.prototype.map()`). **Conclusion** The FizzBuzz benchmark provides a useful comparison of different approaches for generating the sequence, highlighting both pros and cons of each option. By understanding the performance characteristics of these approaches, developers can make informed decisions about which method to use in their own applications, taking into account factors like readability, maintainability, and performance requirements.
Related benchmarks:
Class vs ID
matchAll vs exec
matchAll vs exec v2
replace vs exec v2
string comparisons 4
Comments
Confirm delete:
Do you really want to delete benchmark?