Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes vs array.indexOf (string values) (larger array)
(version: 0)
Comparing performance of:
includes vs set lookup vs indexof
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = [ '37241', '96319', '52521', '16796', '87238', '39323', '27422', '78861', '81540', '26141', '74036', '8303', '40329', '80380', '28341', '28535', '94356', '21929', '70975', '98537', '21501', '92484', '76106', '44172', '665', '40245', '71772', '55320', '89832', '32229', '7304', '49297', '90851', '53689', '56748', '67062', '34113', '15361', '2289', '58200', '38020', '89356', '87300', '31974', '64847', '845', '68298', '25015', '54251', '38934', '11187', '2369', '28441', '64364', '85695', '5919', '92528', '71464', '97459', '47787', '64679', '30597', '62341', '42741', '76494', '88530', '68824', '2687', '37601', '63412', '47751', '8369', '92027', '16061', '24488', '8770', '8300', '23375', '21438', '72630', '92509', '75681', '63572', '93839', '47026', '32125', '20530', '13655', '76497', '49878', '99364', '45033', '97440', '16391', '79167', '99069', '26298', '68934', '14747', '21457', '61073', '29848', '77268', '4100', '16401', '24507', '45303', '83745', '62804', '81564', '19502', '9722', '49883', '89558', '55945', '35359', '9066', '44952', '67710', '95944', '94903', '27919', '10125', '56451', '4187', '18930', '74652', '57167', '41531', '65896', '77043', '73464', '7407', '64455', '1850', '38006', '89774', '44339', '26733', '75224', '13006', '85492', '22483', '66549', '69263', '99496', '10651', '61043', '25884', '31556', '31714', '71374', '80413', '85557', '88927', '79710', '93793', '6453', '28511', '73630', '63316', '88249', '68838', '12549', '23654', '85430', '19949', '36938', '12337', '13660', '73739', '19337', '88910', '55152', '61634', '35095', '94093', '53976', '25265', '72575', '68584', '46164', '37418', '90329', '9464', '21276', '54760', '15145', '39863', '95204', '90533', '28253', '32941', '84199', '35499', '54816', '46668', '5244', '44675', '39585', '82033', '19748', '77991', '78937', '55524', '29417', '51724', '2206', '34282', '85394', '1602', '64661', '45571', '27832', '87572', '44452', '53533', '40522', '985', '29454', '41842', '37534', '71051', '21307', '2040', '28310', '94203', '20364', '56626', '36067', '24594', '3817', '99158', '74740', '81174', '16583', '94423', '60072', '44335', '46024', '19190', '9299', '11817', '72929', '37118', '45504', '56345', '7610', '25020', '85835', '58474', '91075', '91350', '3565', '2189', '54590', '38617', '60255', '83487', '14380', '44759', '3705', '93542', '55619', '79873', '22785', '70772', '77124', '15265', '951', '86164', '36567', '37202', '22886', '5255', '16517', '25144', '27928', '32354', '82417', '34082', '27432', '89110', '48559', '59596', '19817', '67643', '26704', '42770', '24023', '13978', '49390', '37656', '17095', '2783', '94873', '94280', '20976', '2374', '98549', ];
Tests:
includes
return a.includes('63412')
set lookup
var b = new Set(a) return b.has('63412')
indexof
return a.indexOf('63412') >= 0
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
includes
set lookup
indexof
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 break down the benchmark and its test cases. **Benchmark Definition** The benchmark definition is not provided, but based on the individual test cases, we can infer that it involves looking up a value in an array or set to determine whether it exists. **Individual Test Cases** There are three test cases: 1. **"includes"`**: This test case checks if the `a` array contains a specific value (`'63412'`) using the `includes()` method. 2. **"set lookup"`**: This test case creates a new Set object from the `a` array and then looks up a specific value (`'63412'`) in it using the `has()` method. 3. **"indexof"`**: This test case checks if the `a` array contains a specific index that corresponds to a particular value (`'63412'`) using the `indexOf()` method. **Latest Benchmark Result** The latest benchmark result shows the execution times for each test case across different browsers and devices: 1. **"includes"`**: The fastest execution time is 6.9295 milliseconds, achieved by Chrome 107 on a desktop Windows device. 2. **"indexof"`**: The fastest execution time is 3.4214 milliseconds, also achieved by Chrome 107 on a desktop Windows device. 3. **"set lookup"`**: The fastest execution time is 1.4236 milliseconds, again achieved by Chrome 107 on a desktop Windows device. **Comparison** Based on the benchmark results, it appears that: * `includes()` is slower than both `indexof()` and `set lookup()`. * `indexof()` is faster than `set lookup()`. * Both `indexof()` and `set lookup()` are significantly faster than `includes()`. It's worth noting that these results may vary depending on the specific implementation and optimizations used by each browser. However, based on this benchmark, it seems that `indexof()` and `set lookup()` are generally faster than `includes()`.
Related benchmarks:
set.has vs. array.includes (with big array)
set.has vs. array.includes (with big array and last index match)
set.has vs. array.includes (300 elements)
set.has vs. array.includes vs array.indexOf (string values) - 800 ids
Comments
Confirm delete:
Do you really want to delete benchmark?