Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
sgdfgdgd
(version: 0)
sdfgdfg
Comparing performance of:
number vs string
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
function intersect(arrays) { const response = arrays.length === 1 ? [...arrays[0]] : []; if (arrays.length > 1) { const nOthers = arrays.length - 1; let nShortest = arrays[0].length; let shortest = 0; for (let i = 0; i <= nOthers; i++) { const n = arrays[i].length; if (n < nShortest) { shortest = i; nShortest = n; } } let len; const obj = {}; for (let i = 0; i <= nOthers; i++) { const n = i === shortest ? 0 : i || shortest; //Read the shortest array first. Read the first array instead of the shortest len = arrays[n].length; for (let j = 0; j < len; j++) { const item = arrays[n][j]; if (obj[item] === i - 1) { if (i === nOthers) { response[response.length] = item; obj[item] = 0; } else { obj[item] = i; } } else if (i === 0) { obj[item] = 0; } } } } return response; } n1 = [24005, 18321, 478, 1113369]; n2 = []; s1 = n1.map(i => `${i}`); s2 = []; for (let i = 0; i < 100000; i++) { n2.push(i); s2.push(`${i}`); }
Tests:
number
intersect([n1, n2])
string
intersect([s1, s2])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
number
string
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
number
405.2 Ops/sec
string
369.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and explain what is being tested. **Benchmark Definition** The benchmark definition is an object with two properties: `Benchmark Definition` and `Script Preparation Code`. The `Benchmark Definition` property defines the test case, which in this case is a JavaScript function call to the `intersect()` function. The `Script Preparation Code` property provides the initial code for the script before running the benchmark. **What is being tested?** The benchmark tests two different scenarios: 1. `number`: This test case passes an array of numbers (`n1`) and an empty array (`n2`) to the `intersect()` function. 2. `string`: This test case passes an array of strings (`s1`) and an empty array (`s2`) to the `intersect()` function. **Options being compared** In this benchmark, two approaches are compared: * Approach 1: Using arrays of numbers or strings * Approach 2: Using maps of characters (by converting each string to a character array) The benchmark is designed to measure the performance difference between these two approaches. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: * **Approach 1: Arrays** + Pros: - Simple and efficient - Familiar data structure for JavaScript developers + Cons: - May not be optimal for string comparisons, as strings are encoded in Unicode * **Approach 2: Maps of characters** + Pros: - Optimized for string comparisons, as it uses the `charCodeAt()` method to access individual characters + Cons: - Requires more memory and CPU cycles, as it needs to iterate over each character in the string **Library** In this benchmark, no external libraries are used. **Special JS feature or syntax** There is a special feature being tested here: `charCodeAt()`. This method returns the Unicode code point for a one-character string. In Approach 2, this method is used to access individual characters in the strings. **Other considerations** * **Data size**: The benchmark uses large arrays of numbers and strings (100,000 elements each). This may affect the performance results. * **Browser-specific optimizations**: The benchmark uses a specific browser version (Chrome 126) and platform (Windows Desktop). Other browsers or platforms may have different performance characteristics. **Alternatives** Other alternatives for this type of benchmark could include: * Using other data structures, such as sets or trees * Implementing a custom comparison algorithm * Using a different programming language or framework * Adding additional test cases, such as edge cases or multi-threaded scenarios
Related benchmarks:
Array Intersection Comparison
native intersect vs lodash intersection small and large
native intersect vs lodash intersect small and large
native intersect vs lodash intersect small and large 3
Comments
Confirm delete:
Do you really want to delete benchmark?