Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Fizz Buzz#2
(version: 0)
Fizz Buzz perfocmance
Comparing performance of:
For vs Array join vs Array map vs Wtf vs Longread vs For#2 vs Wtf#2 vs For#3 vs 22 Iterations vs Array map#2
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
For
for(i=0;i<100;)console.log((++i%3?'':'Fizz')+(i%5?'':'Buzz')||i)
Array join
console.log( Array.apply(null, {length: 100}).map(function(val, index) { return (++index%3?'':'Fizz')+(index%5?'':'Buzz')||index; }).join('\n') );
Array map
console.log( Array.apply(null, {length: 100}).map(function(val, index) { index++; if (index % 15 == 0){return "FizzBuzz";} if (index % 3 == 0){return "Fizz";} if (index % 5 == 0){return "Buzz";} return index; }).join('\n') );
Wtf
var i, values = [, , 'fizz', , 'buzz', 'fizz', , , 'fizz', 'buzz', , 'fizz', , , 'fizzbuzz']; for (i = 0; i < 100; console.log(values[i++ % 15] || i));
Longread
(function (window) { 'use strict'; var counter = 1; var limit = 100; var options = { 3: 'Fizz', 5: 'Buzz', 'default': function (input) { return input; } }; var noop = function () { return; }; var print = function (input) { var output = []; Object.keys(options).map( function (key) { (((typeof options[key] !== 'function') && ((parseInt(input, 10) % parseInt(key, 10)) === 0)) ? Array.prototype.push : noop).call(output, options[key]); } ); return console.log.call(console, output.length ? output.join('') : options.default.call(this, input)); }; for (; counter <= limit; counter += 1) { print.call(this, counter); } })(this);
For#2
for (var i=0;i<=100;i++) console.log(!(i%15)&&"fizzbuzz"||!(i%5)&&"buzz"||!(i%3)&&"fizz"||i);
Wtf#2
var fizzBuzz = function* () { var i = 0; do { const isFizz = i % 3 === 0; const isBuzz = i % 5 === 0; yield (isFizz ? isBuzz ? "FizzBuzz" : "Fizz" : isBuzz ? "Buzz" : i); } while (++i) } var it = fizzBuzz(); for (let i = 0; i < 100; i++){ console.log(it.next().value); }
For#3
for (var i = 1; i <= 100; i++) { answer = " "; if (i % 3 == 0) { answer += 'Fizz'; } if (i % 5 == 0) { answer += 'Buzz'; } console.log(answer || i); }
22 Iterations
let i = 0 let j = 1 let limit = 100 //prints zero console.log(i); while (true) { if (i > limit - 4) break; //can also kept in loop; but I always enjoy infinte loops breaking ;-) and have to subtract with 4 if needed till 99 i = i + 5; (i - 4) % 3 === 0 ? console.log(i - 4 + " - Fizz") : console.log(i - 4); (i - 3) % 3 === 0 ? console.log(i - 3 + " - Fizz") : console.log(i - 3); (i - 2) % 3 === 0 ? console.log(i - 2 + " - Fizz") : console.log(i - 2); (i - 1) % 3 === 0 ? console.log(i - 1 + " - Fizz") : console.log(i - 1); if (i % 3 === 0) { console.log(i + " - FizzBuzz"); continue } console.log(i + " - Buzz") j++ //Loop Counter } console.log('Total iterations ran: ', j)
Array map#2
console.log( [...Array(100).keys()].map((_, i) => i + 1) .map(i => (i % 3 === 0 && i % 5 === 0) ? "FizzBuzz" : (i % 3 === 0) ? "Fizz" : (i % 5 === 0) ? "Buzz" : i) .join("\n") );
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (10)
Previous results
Fork
Test case name
Result
For
Array join
Array map
Wtf
Longread
For#2
Wtf#2
For#3
22 Iterations
Array map#2
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):
A JSON array of UAT results! To extract meaningful information, I'll skip the preamble and provide some insights on the data. Here are the top 10 results by ExecutionPerSecond: 1. **Array map#2**: 50846.4921875 2. **For**: 1127.8612060546875 3. **For#3**: 1019.4963989257812 4. **Longread**: 863.7236328125 5. **Wtf#2**: 1091.345458984375 6. **Array map**: 49915.84765625 7. **For#2**: 1120.8621826171875 8. **22 Iterations**: 1055.2763671875 9. **Wtf**: 1077.9765625 10. **Array join**: 49161.25390625 These results indicate that: * The most executed test is `Array map#2`, which takes around 50 seconds to execute. * There are two tests tied for second place: `For` and `For#3`, both taking around 1-2 seconds to execute. * Some tests, like `Longread` and `Wtf`, take relatively short times (around 1 minute) to execute. Please note that these results might not be entirely meaningful without context about the specific use cases or scenarios being tested.
Related benchmarks:
HashBounds
HashBounds
FastStringMap test2
modulo vs bitlogic
Template Literals vs String Concatenation vs Replace
Comments
Confirm delete:
Do you really want to delete benchmark?