Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set string vs number
(version: 0)
Compare Set with string and number
Comparing performance of:
String Set vs Index Set
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) }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
String Set
Index Set
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/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
String Set
459.7 Ops/sec
Index Set
888.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided JSON represents a JavaScript microbenchmark on MeasureThat.net, which compares the performance of two approaches: adding unique strings and indices to a Set data structure. **Script Preparation Code** The script preparation code is responsible for generating an array of 10,000 unique random UUIDs using the `crypto.randomUUID()` function. This code is executed before each benchmark test case. **Html Preparation Code** There is no HTML preparation code provided, which means that the browser's default settings and rendering will be used for this benchmark. **Individual Test Cases** The two test cases are: 1. **String Set**: This test case adds 10,000 unique random strings to a Set data structure using the `add()` method. 2. **Index Set**: This test case adds 10,000 integers ( indices) to a Set data structure using the `add()` method. **Library and Purpose** In both test cases, a Set data structure is used from the JavaScript standard library (`Set` object). A Set is a collection of unique values, which allows for efficient lookups and additions. **Special JS Feature/Syntax** There are no special JavaScript features or syntaxes being tested in this benchmark. However, it's worth noting that the use of `crypto.randomUUID()` to generate unique identifiers might be considered a modern JavaScript feature. **Pros and Cons of Approaches** 1. **Adding unique strings to Set**: * Pros: This approach tests the performance of adding unique values to a Set, which is an essential operation in many algorithms. * Cons: Since Sets automatically eliminate duplicates, this approach may not reveal any significant performance differences between the two test cases. 2. **Adding indices to Set**: * Pros: This approach tests the performance of adding integers (indices) to a Set, which can be useful in certain scenarios, such as generating unique row IDs or index-based data structures. * Cons: Since Sets do not maintain any ordering or indexing information, this approach may not provide valuable insights into the performance of Set operations. **Other Considerations** 1. **Cache-friendly operations**: The test cases are likely designed to be cache-friendly, meaning that they minimize the number of memory accesses and cache misses. 2. **Language-level optimizations**: The test cases may also aim to expose language-level optimizations, such as register allocation and instruction scheduling, which can affect performance in certain scenarios. **Alternative Benchmarks** If you'd like to explore alternative benchmarks, MeasureThat.net offers a wide range of microbenchmarking tests, including: * Array operations (e.g., push, pop, splice) * Object operations (e.g., property access, iteration) * String operations (e.g., substring, regex matching) * Math and numerical computations * Regular expressions and pattern matching Keep in mind that each benchmark test case is designed to isolate specific performance characteristics or language features, so you may want to explore these alternatives to gain a deeper understanding of JavaScript's strengths and weaknesses.
Related benchmarks:
set.has vs. array.includes - 1000 UUIDs
UUID Generation compare
Set string vs number #1
Set string vs number (100k)
Comments
Confirm delete:
Do you really want to delete benchmark?