Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set string vs number #1
(version: 0)
Compare Set with string and number
Comparing performance of:
String Set vs Index Set vs Index Set with alignment
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function generateUUIDs(n) { const uuids = []; for (let i = 0; i < n; i++) { uuids.push(crypto.randomUUID()); } return uuids; } // Example usage: const numberOfUUIDs = 10000; var uuids = generateUUIDs(numberOfUUIDs);
Tests:
String Set
const set = new Set() for (let index = 0; index < uuids.length; index++) { const uuid = uuids[index] set.add(uuid) } for (let index = 0; index < uuids.length; index++) { const uuid = uuids[index] set.add(uuid) }
Index Set
const set = new Set() for (let index = 0; index < uuids.length; index++) { set.add(index) } for (let index = 0; index < uuids.length; index++) { set.add(index) }
Index Set with alignment
const set = new Set() for (let index = 0; index < uuids.length; index++) { const uuid = uuids[index] set.add(index) } for (let index = 0; index < uuids.length; index++) { const uuid = uuids[index] set.add(index) }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
String Set
Index Set
Index Set with alignment
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Safari/605.1.15
Browser/OS:
Safari 16 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
String Set
567.7 Ops/sec
Index Set
977.1 Ops/sec
Index Set with alignment
612.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Overview** The provided JSON represents a JavaScript microbenchmark that compares three different approaches for adding elements to a Set data structure: 1. Adding strings 2. Adding numbers (using indices) 3. Adding numbers with alignment (similar to 2, but with additional alignment) **Set Data Structure** A Set in JavaScript is an object that stores unique values, allowing for efficient lookup and removal of elements. Sets are implemented as hash tables under the hood, which means they use a hash function to map keys to indices in an internal array. **Options Compared** The three test cases compare the performance of adding elements to a Set using different data types: * **String Set**: Adding strings to the Set. * **Index Set**: Adding numbers (using indices) to the Set. This approach is similar to the previous one but uses indices instead of actual values. * **Index Set with alignment**: A variant of the Index Set, where additional alignment is applied. **Pros and Cons** Here are some pros and cons of each approach: 1. **String Set**: * Pros: Simple and straightforward implementation. * Cons: May incur additional overhead due to string comparison and hash function calculations. 2. **Index Set**: * Pros: Can take advantage of CPU cache and reduce overhead by using indices instead of actual values. * Cons: Requires careful alignment to ensure optimal performance. 3. **Index Set with alignment**: * Pros: Combines the benefits of the Index Set with additional alignment for better cache locality. * Cons: May add complexity to the implementation. **Library Usage** There is no explicit library usage in this benchmark, as it only uses built-in JavaScript features. **Special JS Features or Syntax** The benchmark uses a few special JavaScript features: * **String interpolation**: Used in the `generateUUIDs` function. * **Arrow functions**: Used in some of the test case scripts. However, these features are not essential to understanding the benchmark's functionality. **Other Alternatives** If you were to rewrite this benchmark using different approaches or languages, here are a few alternatives: * Use a different data structure, such as an array or a linked list. * Compare the performance of adding elements to the Set using different algorithms (e.g., iterative vs. recursive). * Use a different language or platform, such as Python or Node.js. Keep in mind that these alternatives would require significant changes to the benchmark and its implementation.
Related benchmarks:
set.has vs. array.includes - 1000 UUIDs
UUID Generation compare
Set string vs number
Set string vs number (100k)
Comments
Confirm delete:
Do you really want to delete benchmark?