Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
testbench
(version: 0)
besttench
Comparing performance of:
old vs new
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
old
function hueToRGB(h, s, l) { const c = s * (1 - Math.abs(2 * l - 1)); const x = c * (1 - Math.abs((h / 60) % 2 - 1)); const m = l - c / 2; let r = 0; let g = 0; let b = 0; if (0 <= h && h < 60) { r = c; g = x; b = 0; } else if (60 <= h && h < 120) { r = x; g = c; b = 0; } else if (120 <= h && h < 180) { r = 0; g = c; b = x; } else if (180 <= h && h < 240) { r = 0; g = x; b = c; } else if (240 <= h && h < 300) { r = x; g = 0; b = c; } else if (300 <= h && h < 360) { r = c; g = 0; b = x; } return [Math.round((r + m) * 255), Math.round((g + m) * 255), Math.round((b + m) * 255)]; } function textToHtmlRainbow(str) { const frequency = 360 / str.length; return Array.from(str).map((c, i) => { const [r, g, b] = hueToRGB(i * frequency, 1.0, 0.5); return '<font color="#' + r.toString(16).padStart(2, "0") + g.toString(16).padStart(2, "0") + b.toString(16).padStart(2, "0") + '">' + c + '</font>'; }).join(""); } textToHtmlRainbow("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor inci didunt ut labore");
new
function hueToRGB(h, s, l) { const c = s * (1 - Math.abs(2 * l - 1)); const x = c * (1 - Math.abs((h / 60) % 2 - 1)); const m = l - c / 2; let r = 0; let g = 0; let b = 0; function setRGB(a, b, c){ r = a; g = b; b = c; } switch (true) { case h < 60: setRGB(c, x, 0); break; case h < 120: setRGB(x, c, 0); break; case h < 180: setRGB(0, c, x); break; case h < 240: setRGB(0, x, c); break; case h < 300: setRGB(x, 0, c); break; default: setRGB(c, 0, x); break; } return [Math.round((r + m) * 255), Math.round((g + m) * 255), Math.round((b + m) * 255)]; } function textToHtmlRainbow(str) { const s = str.replace(/ /g, ''); const frequency = 360 / s.length; let i = 0; return Array.from(str).map(c => { if (c === ' ') return ' '; const [r, g, b] = hueToRGB(i * frequency, 1.0, 0.5); i++; return '<font color="#' + r.toString(16).padStart(2, "0") + g.toString(16).padStart(2, "0") + b.toString(16).padStart(2, "0") + '">' + c + '</font>'; }).join(""); } textToHtmlRainbow("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor inci didunt ut labore");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
old
new
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'd be happy to help you understand the benchmark being tested on MeasureThat.net. **Benchmark Definition** The benchmark definition is a JSON object that defines two test cases: `testbench` and its individual test case `old`. The `testbench` is the overall benchmark, while `old` is one of the test cases under `testbench`. **Test Case: old** The test case `old` contains two functions: 1. `hueToRGB(h, s, l)`: This function takes three input parameters: hue (`h`), saturation (`s`), and lightness (`l`). It returns a color in the form of an RGB array. 2. `textToHtmlRainbow(str)`: This function takes a string as input and returns an HTML string with rainbow-colored text. The `hueToRGB` function uses a simple formula to calculate the RGB values based on the input hue, saturation, and lightness. The `textToHtmlRainbow` function uses the `hueToRGB` function to generate colors for each character in the input string and then formats them into an HTML string with rainbow-colored text. **Test Case: new** The test case `new` is identical to `old`, except that it has a few differences: 1. The `setRGB` function is defined inside the `hueToRGB` function. 2. The `textToHtmlRainbow` function uses a regular expression to remove spaces from the input string. **Comparison of Options** The benchmark compares two versions of the `textToHtmlRainbow` function: `old` and `new`. The comparison focuses on the performance difference between these two versions. **Pros and Cons of Different Approaches** 1. **Using a separate `setRGB` function (new)**: * Pros: Simplifies the code and makes it easier to maintain. * Cons: Adds overhead due to the additional function call. 2. **Not using a separate `setRGB` function (old)**: * Pros: Reduces overhead due to fewer function calls. * Cons: Makes the code more complex and harder to understand. **Other Considerations** 1. **Library usage**: The benchmark uses the JavaScript console object, which is built-in to most browsers. There are no external libraries used in this benchmark. 2. **Device platform**: The benchmark runs on a desktop device with Windows 10 operating system and Chrome 84 browser. 3. **Browser version**: The benchmark is specific to Chrome 84. **Benchmark Results** The latest benchmark results show that the `new` version of the `textToHtmlRainbow` function executes at approximately 6399 executions per second, while the `old` version executes at approximately 6842 executions per second. In summary, the benchmark compares two versions of a JavaScript function and measures their performance difference. The comparison highlights the trade-offs between simplifying the code vs. reducing overhead due to additional function calls.
Related benchmarks:
domcompare
i++ vs ++i vs i += 1
Nested tenary vs dictionary
list includes vs set has
JS Big Integers v4
Comments
Confirm delete:
Do you really want to delete benchmark?