Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Generate Ticks
(version: 0)
Generate Ticks
Comparing performance of:
ticks1 vs ticks2
Created:
7 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
const e10 = Math.sqrt(50); const e5 = Math.sqrt(10); const e2 = Math.sqrt(2); function generateTicks(start, stop, count) { let reverse; let i = -1; let n; let ticks; let step; stop = +stop; start = +start; count = +count; if (start === stop && count > 0) { return [start]; } if ((reverse = stop < start)) { n = start; start = stop; stop = n; } if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) { return []; } if (step > 0) { start = Math.ceil(start / step); stop = Math.floor(stop / step); ticks = new Array((n = Math.ceil(stop - start + 1))); while (++i < n) ticks[i] = (start + i) * step; } else { start = Math.floor(start * step); stop = Math.ceil(stop * step); ticks = new Array((n = Math.ceil(start - stop + 1))); while (++i < n) ticks[i] = (start - i) / step; } if (reverse) ticks.reverse(); return ticks; } function tickIncrement( start, stop, count, ) { const step = (stop - start) / Math.max(0, count); const power = Math.floor(Math.log(step) / Math.LN10); const error = step / Math.pow(10, power); return power >= 0 ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power) : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1); } function niceNumber(range, round) { const exponent = Math.floor(Math.log10(range)); const fraction = range / Math.pow(10, exponent); let niceFraction; if (round) { if (fraction < 1.5) { niceFraction = 1; } else if (fraction < 3) { niceFraction = 2; } else if (fraction < 7) { niceFraction = 5; } else { niceFraction = 10; } } else { if (fraction <= 1.0) { niceFraction = 1; } else if (fraction <= 2) { niceFraction = 2; } else if (fraction <= 5) { niceFraction = 5; } else { niceFraction = 10; } } return niceFraction * Math.pow(10, exponent); } domain = [1000, 200]; function ticks1(count) { const niceRange = niceNumber(domain[1] - domain[0], false); const spacing = niceNumber(niceRange / (count - 1), true); const niceMin = Math.floor(domain[0] / spacing) * spacing; const niceMax = Math.ceil(domain[1] / spacing) * spacing; // Put the values into the ticks array const ticks = []; for (let j = niceMin; j <= niceMax; j += spacing) { ticks.push(j); } return ticks; } function ticks2(count) { generateTicks(domain[0], domain[1], count) }
Tests:
ticks1
ticks1(12);
ticks2
ticks2(12);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
ticks1
ticks2
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 break down the benchmark and explain what's being tested. **Benchmark Definition** The provided JSON represents a JavaScript microbenchmark named "Generate Ticks". The benchmark is designed to measure the performance of two different functions: `ticks1` and `ticks2`, which generate ticks for a specified range with a given count. **Function `generateTicks`** This function takes three arguments: `start`, `stop`, and `count`. It generates an array of ticks between `start` and `stop` with a step size determined by the `tickIncrement` function. The function also handles cases where the start and stop values are equal or when the count is zero. **Function `tickIncrement`** This function calculates the step size based on the difference between `start` and `stop`, as well as the desired count. It uses logarithmic scaling to determine the step size, which is then adjusted using error estimates (`e10`, `e5`, and `e2`) to ensure accurate results. **Function `niceNumber`** This function takes a range and an optional rounding parameter. It returns a nice number representation of the range by adjusting the decimal places based on the input value. **Functions `ticks1` and `ticks2`** These two functions are test cases for the `generateTicks` function. They take a count as an argument and generate ticks for the specified range using the `generateTicks` function. `ticks1` uses a rounded representation of the range, while `ticks2` uses the exact values. **Comparison** The benchmark compares the performance of `ticks1` (using a rounded representation) and `ticks2` (using exact values) with different counts. **Pros and Cons** * **Rounded representation (`ticks1`):** + Pros: potentially faster execution due to reduced decimal place calculations + Cons: may introduce errors or inaccuracies in the generated ticks * **Exact representation (`ticks2`):** + Pros: more accurate results, but potentially slower execution due to increased calculations + Cons: may lead to performance bottlenecks **Considerations** The benchmark assumes that the input ranges are within a specific domain (`[1000, 200]`). If the range is outside this domain, the `niceNumber` function may not behave as expected. **Other Alternatives** Other approaches to generating ticks could include: * Using a predefined tick spacing or interval * Implementing a more advanced logarithmic scaling algorithm * Utilizing a library or framework for generating ticks However, these alternatives are not currently being tested in this benchmark.
Related benchmarks:
Haversine
Haversine
Set.has v.s Array.includes
yoooooo
Set.has v.s Array.includes v2
Comments
Confirm delete:
Do you really want to delete benchmark?