Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
domino chain alg
(version: 0)
Comparing performance of:
Alex vs Nik
Created:
4 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
const tests = [ [0, ''], [1, '6-3'], [2, '1-2,1-2'], [4, '1-1,3-5,5-2,2-3,2-4'], [8, '2-3,2-1,1-4,4-4,4-4,5-4,4-2,2-1'], [5, '2-3,2-1,1-4,3-3,3-4,5-4,4-2,2-1'], [4, '3-5,2-1,1-4,4-4,4-4,5-3,3-2,2-1'], [7, '3-2,2-1,1-4,4-4,4-4,4-3,3-2,4-5,3-5,2-1,1-4,2-2,4-4,5-3,3-2,2-1'], ]; function run(fn) { tests.forEach(([result, input], i) => { const res = fn(input); console.log(`Test ${1}: '${input}'`); console.log(`Expected: ${result} - ${res === result}`); console.log(res); console.log('============================='); }); }
Tests:
Alex
const domino = (dominoQueue) => { const splitQueue = dominoQueue.split(",").map((item) => { return item.split("-"); }); let countsArr = [0]; for (let i = 0; i < splitQueue.length; i++) { const currentQueueItemArray = splitQueue[i]; const nextQueueItemArray = splitQueue[i + 1]; if (Array.isArray(nextQueueItemArray)) { if (currentQueueItemArray[1] === nextQueueItemArray[0]) { countsArr[countsArr.length - 1] += 1; } else { countsArr[countsArr.length] = 0; } } } return Math.max(...countsArr); }; run(domino);
Nik
function domino(dominoes) { let chains = [0]; if (dominoes) { const chain = dominoes.split(','); let prev = []; let chainI = 0; chain.forEach((item, i) => { const current = item.split('-'); if (!i || (prev.length && prev.some((v) => current.includes(v)))) { chains[chainI]++; } else { chainI++; chains[chainI] = 1; } prev = current; }); } return chains.sort((a, b) => b - a)[0]; } run(domino);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Alex
Nik
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 dive into the world of JavaScript microbenchmarks! **Benchmark Definition JSON** The provided Benchmark Definition JSON represents a benchmark for testing two different algorithms: `domino` and a modified version of it (`modified-domino`). The benchmark is designed to measure the performance of these algorithms in finding the longest domino chain. Here's a breakdown of what's being tested: * **domino**: This algorithm splits the input string into individual dominoes, then iterates through the resulting array to count the number of consecutive dominoes with the same value. The maximum count is returned as the result. * **modified-domino**: This algorithm is identical to `domino`, but with some minor differences in implementation details. **Options being compared** The two algorithms being tested are: 1. `domino`: This algorithm uses a simple approach to split and iterate through the dominoes, resulting in a straightforward but potentially slow execution. 2. **modified-domino**: This algorithm is likely an optimized version of `domino`, with some performance tweaks that may result in faster execution. **Pros and cons of each approach** 1. `domino`: * Pros: Simple to understand and implement, easy to maintain. * Cons: May be slower due to the overhead of repeated string splitting and iteration. 2. **modified-domino**: * Pros: Optimized for performance, may result in faster execution. * Cons: May be more complex to understand and maintain, with potentially hidden performance implications. **Other considerations** * Both algorithms use a similar approach to find consecutive dominoes with the same value, which suggests that the main difference lies in the implementation details. * The benchmark results will likely show some variation between the two algorithms, depending on factors like browser performance, system resources, and algorithmic optimizations. **Library usage** There is no explicit mention of any libraries being used in these benchmarks. However, it's worth noting that both `domino` and `modified-domino` use basic JavaScript functions like `split()`, `map()`, and `forEach()`. **Special JS features or syntax** Neither algorithm explicitly uses any special JavaScript features or syntax beyond the standard features mentioned above. **Other alternatives** If you're interested in exploring alternative approaches, here are some ideas: 1. **Parallel processing**: Split the input array into multiple chunks and process each chunk concurrently using `Web Workers` or a similar approach. 2. **Caching**: Implement caching to store intermediate results and avoid redundant computations. 3. **GPU acceleration**: Utilize GPU-accelerated libraries like WebGL or OpenCL to accelerate domino chain finding. Keep in mind that these alternatives may add complexity to the implementation, but can potentially lead to improved performance.
Related benchmarks:
concat vs spread funcking operator
seewrewrwr
spread vs concat vs unshift vs flat v2
map() vs for...loop using Moore's 3
Comments
Confirm delete:
Do you really want to delete benchmark?