Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test rapidite2
(version: 0)
Comparing performance of:
func 1 vs func 2
Created:
4 years ago
by:
Guest
Jump to the latest result
Tests:
func 1
const input = [ 1, 8, 5, 12, 3, 11, 14, 7, 9, 13, 4, 7, 0, 7, 3, 5, 1, 2, 1, 7, 4, 6, 11, 3, 12, 9, 13, 4, 15, 9, 6, 10, 12, 9, 3, 13, 10, 15, 0, 10, 12, 4, 4, 3, 10, 14, 11, 1, 2, 12, 11, 4, 2, 1, 4, 15, 5, 5, 9, 6, 10, 13, 3, 12, 15, 12, 3, 15, 1, 5, 15, 2, 9, 0, 15, 15, 14, 0, 15, 1, 13, 10, 3, 8, 6, 9, 10, 12, 15, 3, 7, 2, 4, 8, 8, 13, 8, 8, 3, 9, 5, 8, 8, 4, 13, 13, 2, 8, 3, 5, 14, 14, 3, 12, 13, 1, 10, 2, 10, 12, 12, 3, 15, 6, 9, 8, 15, 13, 9, 9, 11, 5, 14, 4, 13, 3, 3, 8, 13, 15, 10, 13, 6, 6, 12, 10, 5, 15, 11, 12, 8, 8, 7, 4, 0, 5, 4, 12, 9, 11, 11, 15, 2, 5, 12, 10, 6, 7, 9, 10, 14, 14, 14, 0, 13, 10, 14, 2, 5, 12, 8, 15, 1, 8, 8, 7, 0, 3, 15, 15, 10, 13, 7, 1, 5, 1, 5, 7, 14, 0, 10, 11, 7, 13, 15, 13, 9, 5, 5, 1, 9, 8, 1, 15, 9, 14, 0, 1, 11, 10, 8, 0, 9, 0, 4, 1, 7, 4, 11, 14, 15, 7, 10, 5, 10, 8, 12, 13, 0, 8, 15, 2, 11, 1, 8, 5, 8, 15, 14, 10, 2, 15, 3, 5, 7, 12, 10, 7, 9, 5, 11, 6, 7, 15, 4, 12, 9, 2, 11, 12, 11, 1, 1, 11, 3, 4, 11, 14, 6, 1, 6, 5, 6, 3, 3, 7, 8, 5, 0, 7, 2, 14, 3, 8, 11, 0, 8, 11, 4, 11, 6, 0, 6, 1, 1, 8, 14, 4, 6, 6, 3, 1, 12, 10, 8, 5, 6, 4, 5, 8, 13, 5, 14, 10, 5, 13, 2, 7, 0, 15, 7, 8, 10, 1, 6, 8, 1, 11, 0, 14, 8, 8, 8, 5, 3, 0, 13, 13, 5, 9, 0, 6, 8, 1, 7, 9, 5, 6, 13, 9, 8, 2, 15, 8, 2, 4, 0, 11, 13, 2, 3, 4, 10, 1, 14, 15, 8, 5, 1, 5, 14, 11, 9, 5, 14, 7, 9, 4, 7, 3, 4, 15, 10, 10, 11, 7, 14, 1, 2, 10, 10, 6, 12, 1, 0, 3, 11, 6, 0, 2, 7, 6, 3, 7, 1, 0, 10, 13, 11, 2, 6, 3, 8, 10, 14, 1, 14, 12, 3, 3, 1, 14, 9, 5, 8, 5, 4, 7, 8, 15, 13, 9, 8, 15, 10, 0, 5, 5, 10, 12, 4, 7, 4, 7, 4, 8, 4, 1, 15, 10, 0, 1, 8, 12, 10, 6, 10, 4, 6, 4, 3, 5, 7, 3, 1, 6, 7, 6, 13, 0, 4, 2, 14, 4, 9, 10, 14, 7, 1, 6, 15, 0, 14, 6, 15, 5, 5, 2, 0, 7, 11, 3, 2, 6, 0, 4, 9, 2, 15, 5, 7, 3, 6, 5, 3, 13, 3, 0, 10, 12, 5, 15, 14, 8, 0, 11, 15, 2, 11, 14, 4, 0, 0, 6, 3, 4, 10, 13, 7, 11, 5, 5, 13, 1, 13, 14, 7, 15, 11, 5, 15, 12, 5, 12, 6, 1, 15, 6, 7, 4, 11, 1, 12, 10, 4, 5, 0, 5, 7, 9, 1, 3, 9, 7, 7, 8, 7, 15, 7, 1, 12, 9, 6, 11, 9, 4, 2, 3, 1, 3, 15, 0, 9, 3, 10, 3, 6, 11, 10, 10, 4, 12, 5, 0, 0, 10, 7, 4, 6, 9, 11, 12, 2, 7, 10, 0, 10, 7, 7, 12, 14, 9, 5, 0, 14, 15, 12, 8, 7, 3, 9, 4, 10, 13, 1, 15, 10, 4, 12, 12, 10, 2, 15, 5, 9, 15, 10, 2, 8, 6, 6, 6, 0, 11, 11, 15, 1, 4, 10, 11, 15, 1, 11, 13, 14, 6, 13, 11, 1, 7, 9, 2, 9, 8, 9, 7, 0, 2, 7, 10, 5, 14, 14, 0, 5, 9, 2, 12, 13, 10, 14, 7, 2, 0, 9, 8, 15, 1, 6, 3, 8, 12, 9, 6, 9, 15, 2, 14, 0, 13, 10, 15, 6, 4, 9, 5, 12, 14, 1, 6, 5, 9, 14, 0, 12, 3, 4, 7, 4, 0, 9, 6, 11, 15, 13, 7, 13, 10, 1, 13, 12, 1, 5, 1, 15, 9, 12, 13, 10, 3, 9, 9, 14, 15, 10, 0, 11, 5, 6, 4, 12, 3, 3, 15, 5, 11, 0, 7, 9, 10, 12, 11, 13, 1, 12, 5, 3, 12, 4, 1, 10, 1, 10, 2, 14, 15, 12, 8, 12, 1, 5, 15, 13, 11, 8, 7, 4, 15, 7, 13, 3, 6, 15, 7, 6, 1, 2, 8, 5, 2, 2, 14, 12, 14, 2, 12, 3, 11, 4, 0, 4, 4, 13, 12, 3, 15, 6, 2, 6, 15, 15, 2, 4, 14, 2, 1, 5, 15, 2, 4, 4, 9, 8, 7, 10, 2, 0, 13, 9, 14, 2, 10, 1, 6, 9, 14, 10, 11, 10, 1, 7, 3, 2, 9, 6, 2, 0, 8, 2, 11, 4, 8, 4, 3, 4, 4, 11, 2, 10, 5, 0, 2, 4, 12, 0, 9, 11, 0, 12, 3, 15, 6, 11, 0, 1, 13, 11, 13, 5, 10, 7, 15, 13, 10, 6, 4, 7, 4, 1, 1, 2, 13, 2, 1, 2, 7, 6, 5, 12, 13, 1, 0, 8, 12, 4, 7, 6, 11, 11, 8, 5, 3, 13, 15, 7, 2, 6, 4, 10, 13, 7, 8, 6, 4, 9, 5, 11, 7, 10, 13, 0, 7, 3, 5, 12, 12, 3, 0, 5, 2, 7, 0, 2, 11, 11, 12, 15, 8, 3, 2, 7, 6, 1, 15, 1, 11, 13, 12, 0, 2, 0, 9, 7, 13, 1, 2, 6, 14, 6, 2, 7, 1, 12, 2, 2, 3, 3, 3, 8, 4 ] const twoSum = (array, goal) => { let indexes = []; let count = 0; for(let i = 0; i < array.length; i++){ for(let j = i + 1; j < array.length; j++){ count++; if (array[i] + array[j] === goal) { indexes.push(i); indexes.push(j); console.log("Func 1 => " + count); return indexes; } } } return indexes; } console.log(twoSum(input, 18));
func 2
const input = [ 1, 8, 5, 12, 3, 11, 14, 7, 9, 13, 4, 7, 0, 7, 3, 5, 1, 2, 1, 7, 4, 6, 11, 3, 12, 9, 13, 4, 15, 9, 6, 10, 12, 9, 3, 13, 10, 15, 0, 10, 12, 4, 4, 3, 10, 14, 11, 1, 2, 12, 11, 4, 2, 1, 4, 15, 5, 5, 9, 6, 10, 13, 3, 12, 15, 12, 3, 15, 1, 5, 15, 2, 9, 0, 15, 15, 14, 0, 15, 1, 13, 10, 3, 8, 6, 9, 10, 12, 15, 3, 7, 2, 4, 8, 8, 13, 8, 8, 3, 9, 5, 8, 8, 4, 13, 13, 2, 8, 3, 5, 14, 14, 3, 12, 13, 1, 10, 2, 10, 12, 12, 3, 15, 6, 9, 8, 15, 13, 9, 9, 11, 5, 14, 4, 13, 3, 3, 8, 13, 15, 10, 13, 6, 6, 12, 10, 5, 15, 11, 12, 8, 8, 7, 4, 0, 5, 4, 12, 9, 11, 11, 15, 2, 5, 12, 10, 6, 7, 9, 10, 14, 14, 14, 0, 13, 10, 14, 2, 5, 12, 8, 15, 1, 8, 8, 7, 0, 3, 15, 15, 10, 13, 7, 1, 5, 1, 5, 7, 14, 0, 10, 11, 7, 13, 15, 13, 9, 5, 5, 1, 9, 8, 1, 15, 9, 14, 0, 1, 11, 10, 8, 0, 9, 0, 4, 1, 7, 4, 11, 14, 15, 7, 10, 5, 10, 8, 12, 13, 0, 8, 15, 2, 11, 1, 8, 5, 8, 15, 14, 10, 2, 15, 3, 5, 7, 12, 10, 7, 9, 5, 11, 6, 7, 15, 4, 12, 9, 2, 11, 12, 11, 1, 1, 11, 3, 4, 11, 14, 6, 1, 6, 5, 6, 3, 3, 7, 8, 5, 0, 7, 2, 14, 3, 8, 11, 0, 8, 11, 4, 11, 6, 0, 6, 1, 1, 8, 14, 4, 6, 6, 3, 1, 12, 10, 8, 5, 6, 4, 5, 8, 13, 5, 14, 10, 5, 13, 2, 7, 0, 15, 7, 8, 10, 1, 6, 8, 1, 11, 0, 14, 8, 8, 8, 5, 3, 0, 13, 13, 5, 9, 0, 6, 8, 1, 7, 9, 5, 6, 13, 9, 8, 2, 15, 8, 2, 4, 0, 11, 13, 2, 3, 4, 10, 1, 14, 15, 8, 5, 1, 5, 14, 11, 9, 5, 14, 7, 9, 4, 7, 3, 4, 15, 10, 10, 11, 7, 14, 1, 2, 10, 10, 6, 12, 1, 0, 3, 11, 6, 0, 2, 7, 6, 3, 7, 1, 0, 10, 13, 11, 2, 6, 3, 8, 10, 14, 1, 14, 12, 3, 3, 1, 14, 9, 5, 8, 5, 4, 7, 8, 15, 13, 9, 8, 15, 10, 0, 5, 5, 10, 12, 4, 7, 4, 7, 4, 8, 4, 1, 15, 10, 0, 1, 8, 12, 10, 6, 10, 4, 6, 4, 3, 5, 7, 3, 1, 6, 7, 6, 13, 0, 4, 2, 14, 4, 9, 10, 14, 7, 1, 6, 15, 0, 14, 6, 15, 5, 5, 2, 0, 7, 11, 3, 2, 6, 0, 4, 9, 2, 15, 5, 7, 3, 6, 5, 3, 13, 3, 0, 10, 12, 5, 15, 14, 8, 0, 11, 15, 2, 11, 14, 4, 0, 0, 6, 3, 4, 10, 13, 7, 11, 5, 5, 13, 1, 13, 14, 7, 15, 11, 5, 15, 12, 5, 12, 6, 1, 15, 6, 7, 4, 11, 1, 12, 10, 4, 5, 0, 5, 7, 9, 1, 3, 9, 7, 7, 8, 7, 15, 7, 1, 12, 9, 6, 11, 9, 4, 2, 3, 1, 3, 15, 0, 9, 3, 10, 3, 6, 11, 10, 10, 4, 12, 5, 0, 0, 10, 7, 4, 6, 9, 11, 12, 2, 7, 10, 0, 10, 7, 7, 12, 14, 9, 5, 0, 14, 15, 12, 8, 7, 3, 9, 4, 10, 13, 1, 15, 10, 4, 12, 12, 10, 2, 15, 5, 9, 15, 10, 2, 8, 6, 6, 6, 0, 11, 11, 15, 1, 4, 10, 11, 15, 1, 11, 13, 14, 6, 13, 11, 1, 7, 9, 2, 9, 8, 9, 7, 0, 2, 7, 10, 5, 14, 14, 0, 5, 9, 2, 12, 13, 10, 14, 7, 2, 0, 9, 8, 15, 1, 6, 3, 8, 12, 9, 6, 9, 15, 2, 14, 0, 13, 10, 15, 6, 4, 9, 5, 12, 14, 1, 6, 5, 9, 14, 0, 12, 3, 4, 7, 4, 0, 9, 6, 11, 15, 13, 7, 13, 10, 1, 13, 12, 1, 5, 1, 15, 9, 12, 13, 10, 3, 9, 9, 14, 15, 10, 0, 11, 5, 6, 4, 12, 3, 3, 15, 5, 11, 0, 7, 9, 10, 12, 11, 13, 1, 12, 5, 3, 12, 4, 1, 10, 1, 10, 2, 14, 15, 12, 8, 12, 1, 5, 15, 13, 11, 8, 7, 4, 15, 7, 13, 3, 6, 15, 7, 6, 1, 2, 8, 5, 2, 2, 14, 12, 14, 2, 12, 3, 11, 4, 0, 4, 4, 13, 12, 3, 15, 6, 2, 6, 15, 15, 2, 4, 14, 2, 1, 5, 15, 2, 4, 4, 9, 8, 7, 10, 2, 0, 13, 9, 14, 2, 10, 1, 6, 9, 14, 10, 11, 10, 1, 7, 3, 2, 9, 6, 2, 0, 8, 2, 11, 4, 8, 4, 3, 4, 4, 11, 2, 10, 5, 0, 2, 4, 12, 0, 9, 11, 0, 12, 3, 15, 6, 11, 0, 1, 13, 11, 13, 5, 10, 7, 15, 13, 10, 6, 4, 7, 4, 1, 1, 2, 13, 2, 1, 2, 7, 6, 5, 12, 13, 1, 0, 8, 12, 4, 7, 6, 11, 11, 8, 5, 3, 13, 15, 7, 2, 6, 4, 10, 13, 7, 8, 6, 4, 9, 5, 11, 7, 10, 13, 0, 7, 3, 5, 12, 12, 3, 0, 5, 2, 7, 0, 2, 11, 11, 12, 15, 8, 3, 2, 7, 6, 1, 15, 1, 11, 13, 12, 0, 2, 0, 9, 7, 13, 1, 2, 6, 14, 6, 2, 7, 1, 12, 2, 2, 3, 3, 3, 8, 4 ] const twoSum2 = (array, goal) => { let mapOfNumbers = {}; let twoIndexes = []; let count = 0; for (let i = 0; i < array.length; i++) { mapOfNumbers[array[i]] = i; } for (let i = 0; i < array.length; i++) { count++; let target = goal - array[i]; if(mapOfNumbers[target] !== i && mapOfNumbers[target] !== undefined) { twoIndexes.push(i); twoIndexes.push(mapOfNumbers[target]); console.log("Func 2 => " + count); return twoIndexes; } } console.log("Func 2 => " + count); return twoIndexes; } console.log(twoSum2(input, 18));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
func 1
func 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):
Based on the provided code and benchmark results, I can help you analyze the performance of the `twoSum2` function. The code is written in JavaScript and uses a simple approach to find two elements in an array that add up to a given goal. The function iterates through the array twice: once to create a map of numbers with their indices, and again to check for pairs that sum up to the goal. The benchmark results show two different browsers running two test functions (`func 1` and `func 2`). The first test function has an execution rate of approximately 22,000 executions per second, while the second test function has a significantly lower execution rate of around 11,000 executions per second. After analyzing the code and benchmark results, I have identified a few potential areas for optimization: 1. **Cache Misses:** The `mapOfNumbers` object is created during the first iteration through the array, which involves iterating over the entire array (n) times. This can result in significant cache misses, leading to slower performance. 2. **Redundant Comparisons:** In the second loop, the function checks if a number and its negation are both defined and not equal to the current index. This can be optimized by storing the indices of the numbers we've already checked in a separate array, so that we avoid redundant comparisons. To improve performance, I would suggest implementing these optimizations: * Use a data structure like `WeakMap` or `Object.create(null)` to create the `mapOfNumbers` object. This can help reduce cache misses by using a more efficient storage mechanism. * Store the indices of numbers we've already checked in an array, so that we avoid redundant comparisons. Here's an updated version of the code incorporating these optimizations: ```javascript const twoSum2 = (array, goal) => { let mapOfNumbers = new WeakMap(); let twoIndexes = []; let count = 0; for (let i = 0; i < array.length; i++) { mapOfNumbers.set(array[i], i); } for (let i = 0; i < array.length; i++) { count++; let target = goal - array[i]; if (!mapOfNumbers.has(target) || mapOfNumbers.get(target) === i) continue; twoIndexes.push(i); twoIndexes.push(mapOfNumbers.get(target)); console.log(`Func 2 => ${count}`); return twoIndexes; } console.log(`Func 2 => ${count}`); return twoIndexes; } ``` By implementing these optimizations, we can potentially improve the performance of the `twoSum2` function. However, please note that this is just a suggested improvement and may not necessarily result in significant performance gains depending on the specific use case and input data.
Related benchmarks:
splice VS shift VS splice bulk
blahhhh
Test slice vs splice
slice VS splice - 222222
slice VS splice many items
Comments
Confirm delete:
Do you really want to delete benchmark?