Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
pedroac Fizz Buzz
(version: 4)
Comparing performance of:
direct vs ordered direct vs divisible by 15 vs concatenate vs skip iterations vs functional vs binary
Created:
4 years ago
by:
Registered User
Jump to the latest result
Tests:
direct
const fizzBuzz = function(n) { const result = []; for (let i = 1; i <= n; ++i) { let s = i.toString(); if (i % 3 === 0) { s = 'Fizz'; } if (i % 5 === 0) { s = 'Buzz'; } if (i % 3 === 0 && i % 5 === 0) { s = 'FizzBuzz'; } result.push(s); } return result; } fizzBuzz(100);
ordered direct
const fizzBuzz = function(n) { const result = []; for (let i = 1; i <= n; ++i) { if (i % 3 === 0 && i % 5 === 0) { result.push('FizzBuzz'); } else if (i % 3 === 0) { result.push('Fizz'); } else if (i % 5 === 0) { result.push('Buzz'); } else { result.push(i.toString()); } } return result; }; fizzBuzz(100);
divisible by 15
const fizzBuzz = function(n) { const result = []; for (let i = 1; i <= n; ++i) { if (i % 15 === 0) { result.push('FizzBuzz'); } else if (i % 3 === 0) { result.push('Fizz'); } else if (i % 5 === 0) { result.push('Buzz'); } else { result.push(i.toString()); } } return result; }; fizzBuzz(100);
concatenate
const fizzBuzz = function(n) { const result = []; for (let i = 1; i <= n; ++i) { let str = ''; if (i % 3 === 0) { str += 'Fizz'; } if (i % 5 === 0) { str += 'Buzz'; } if (!str) { str = i.toString(); } result.push(str); } return result; }; fizzBuzz(100);
skip iterations
const fizzBuzz = function(n) { const result = Array(n).fill(''); for (let i = 2; i < n; i += 3) { result[i] += 'Fizz'; } for (let i = 4; i < n; i += 5) { result[i] += 'Buzz'; } for (let i = 0; i < n; ++i) { if (!result[i]) { result[i] = (i+1).toString(); } } return result; } fizzBuzz(100);
functional
const fizzBuzz = function(n) { return Array .from({length: n}, (_,i) => ++i) .map(number => { const f = number % 3 === 0 ? 'Fizz' : ''; const b = number % 5 === 0 ? 'Buzz' : ''; return `${f}${b}` || number.toString(); }); }; fizzBuzz(100);
binary
const fizzBuzz = function(n) { const result = []; const values = [null, 'Fizz', 'Buzz', 'FizzBuzz']; for (let i = 1; i <= n; ++i) { values[0] = i.toString(); result.push( values[(i % 3 === 0) + 2 * (i % 5 === 0)] ); } return result; }; fizzBuzz(100);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (7)
Previous results
Fork
Test case name
Result
direct
ordered direct
divisible by 15
concatenate
skip iterations
functional
binary
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):
I'll do my best to help. It appears that the provided output is in JSON format, representing benchmarking results for various JavaScript functions. Each object in the array contains information about a specific test run, including: 1. `RawUAString`: The raw UA string of the browser. 2. `Browser`: The name of the browser. 3. `DevicePlatform`: The device platform (e.g., Desktop). 4. `OperatingSystem`: The operating system. 5. `ExecutionsPerSecond`: The number of executions per second for the test run. The tests are categorized into different types, such as: * `cached` * `skip iterations` * `ordered direct` * `divisible by 15` * `concatenate` * `direct` * `binary` * `functional` There is also a comment about skipping preambles. Could you please clarify or provide more context about what this means? Which specific question would you like me to answer?
Related benchmarks:
match vs include vs indexOf
test vs include vs indexOf
String manipulation performance test v2
bench hubble .startsWith() vs .test() vs .match() vs .indexOf()
JS string compare
Comments
Confirm delete:
Do you really want to delete benchmark?