Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
uniq vs Set large
(version: 0)
Comparing performance of:
_.uniq vs Array.from(new Set(somearray))
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
Script Preparation code:
var a = [19005,93123,19017,21127,93147,21238,93109,21211,21192,21250,21142,93097,21108,22251,21056,21254,21104,21252,21160,19014,93005,19258,93060,21073,21109,19010,21166,21091,21046,22134,21120,21234,93115,21240,22104,21249,21070,93090,21059,21169,93059,93104,21023,21058,21061,21068,21230,22182,22179,21203,21060,21097,22175,21069,21083,21256,93145,19254,21175,93022,93148,21040,21093,21101,21212,21244,21266,21079,21087,21172,21176,21247,93137,21198,21086,21035,21155,21138,19257,21082,21034,21181,21144,21206,21188,21189,21215,21241,21259,21216,21076,21107,93024,21071,21045,21139,21151,21140,21074,21223,21236,21174,21222,22157,21209,93002,21214,21263,19011,21057,22174,19012,21006,21123,21150,21111,21116,21141,21199,21081,21147,21264,93010,21258,21112,21119,21136,21049,21124,21224,21042,21110,21094,21114,21013,93078,21146,21092,19022,21106,21202,21153,21148,21187,21237,21055,21067,21220,21084,21260,21183,21182,21232,22236,21157,21164,19264,21225,21190,21143,21204,19253,21062,21137,19252,22202,21117,19018,21233,21221,21085,22100,19025,19263,93061,1111,19007,20268,21019,21044,21048,21050,21054,21096,21099,21100,21103,21122,21128,21131,21134,21170,21171,21177,21180,21184,21185,21186,21200,19005,93123,19017,21127,93147,21238,93109,21211,21192,21250,21142,93097,21108,22251,21056,21254,21104,21252,21160,19014,93005,19258,93060,21073,21109,19010,21166,21091,21046,22134,21120,21234,93115,21240,22104,21249,21070,93090,21059,21169,93059,93104,21023,21058,21061,21068,21230,22182,22179,21203,21060,21097,22175,21069,21083,21256,93145,19254,21175,93022,93148,21040,21093,21101,21212,21244,21266,21079,21087,21172,21176,21247,93137,21198,21086,21035,21155,21138,19257,21082,21034,21181,21144,21206,21188,21189,21215,21241,21259,21216,21076,21107,93024,21071,21045,21139,21151,21140,21074,21223,21236,21174,21222,22157,21209,93002,21214,21263,19011,21057,22174,19012,21006,21123,21150,21111,21116,21141,21199,21081,21147,21264,93010,21258,21112,21119,21136,21049,21124,21224,21042,21110,21094,21114,21013,93078,21146,21092,19022,21106,21202,21153,21148,21187,21237,21055,21067,21220,21084,21260,21183,21182,21232,22236,21157,21164,19264,21225,21190,21143,21204,19253,21062,21137,19252,22202,21117,19018,21233,21221,21085,22100,19025,19263,93061,1111,19007,20268,21019,21044,21048,21050,21054,21096,21099,21100,21103,21122,21128,21131,21134,21170,21171,21177,21180,21184,21185,21186,21200,19005,93123,19017,21127,93147,21238,93109,21211,21192,21250,21142,93097,21108,22251,21056,21254,21104,21252,21160,19014,93005,19258,93060,21073,21109,19010,21166,21091,21046,22134,21120,21234,93115,21240,22104,21249,21070,93090,21059,21169,93059,93104,21023,21058,21061,21068,21230,22182,22179,21203,21060,21097,22175,21069,21083,21256,93145,19254,21175,93022,93148,21040,21093,21101,21212,21244,21266,21079,21087,21172,21176,21247,93137,21198,21086,21035,21155,21138,19257,21082,21034,21181,21144,21206,21188,21189,21215,21241,21259,21216,21076,21107,93024,21071,21045,21139,21151,21140,21074,21223,21236,21174,21222,22157,21209,93002,21214,21263,19011,21057,22174,19012,21006,21123,21150,21111,21116,21141,21199,21081,21147,21264,93010,21258,21112,21119,21136,21049,21124,21224,21042,21110,21094,21114,21013,93078,21146,21092,19022,21106,21202,21153,21148,21187,21237,21055,21067,21220,21084,21260,21183,21182,21232,22236,21157,21164,19264,21225,21190,21143,21204,19253,21062,21137,19252,22202,21117,19018,21233,21221,21085,22100,19025,19263,93061,1111,19007,20268,21019,21044,21048,21050,21054,21096,21099,21100,21103,21122,21128,21131,21134,21170,21171,21177,21180,21184,21185,21186,21200];
Tests:
_.uniq
_.uniq(a)
Array.from(new Set(somearray))
Array.from(new Set(a))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.uniq
Array.from(new Set(somearray))
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.uniq
53622.1 Ops/sec
Array.from(new Set(somearray))
145329.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
A complex data processing challenge! Based on the provided information, I'll break down the problem into smaller parts and provide step-by-step solutions. **Step 1: Preprocess the input data** The input `a` is an array of integers: ``` [19007, 20268, 21019, ...] ``` We need to convert this array into a format that can be used by the `_uniq` function. Assuming the `_uniq` function expects an array with no duplicate elements, we'll use the `Array.from(new Set(a))` approach. **Step 2: Implement the `_uniq` function** The `_uniq` function should return an array with unique elements: ```javascript function _uniq(arr) { return Array.from(new Set(arr)); } ``` This implementation uses the `Set` data structure to remove duplicates and then converts it back to an array using `Array.from`. **Step 3: Implement the benchmarking logic** We'll create two test cases: 1. Benchmarking `_.uniq(a)` 2. Benchmarking `Array.from(new Set(somearray))` For each test case, we'll execute the corresponding function and measure its execution time. **Test Case 1: `_uniq(a)`** ```javascript const a = [...]; // input array function _uniq(a) { return Array.from(new Set(a)); } // Benchmarking logic const startTime = performance.now(); const result = _uniq(a); const endTime = performance.now(); console.log(`_uniq(a) execution time: ${endTime - startTime}ms`); ``` **Test Case 2: `Array.from(new Set(somearray))`** ```javascript const somearray = [...]; // input array function somefunc(arr) { return Array.from(new Set(arr)); } // Benchmarking logic const startTime = performance.now(); const result = somefunc(somearray); const endTime = performance.now(); console.log(`Array.from(new Set(somearray)) execution time: ${endTime - startTime}ms`); ``` **Step 4: Run the benchmarking tests** We'll execute both test cases and measure their execution times. We'll assume that the input arrays `a` and `somearray` are already populated with data. Using the latest benchmark result: ```javascript const a = [...]; // input array function _uniq(a) { return Array.from(new Set(a)); } // Benchmarking logic const startTime = performance.now(); const result = _uniq(a); const endTime = performance.now(); console.log(`_uniq(a) execution time: ${endTime - startTime}ms`); const somearray = [...]; // input array function somefunc(arr) { return Array.from(new Set(arr)); } // Benchmarking logic const startTime = performance.now(); const result = somefunc(somearray); const endTime = performance.now(); console.log(`Array.from(new Set(somearray)) execution time: ${endTime - startTime}ms`); ``` Assuming the latest benchmark result: ```javascript [ { "RawUAString": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", "Browser": "Chrome 124", "DevicePlatform": "Desktop", "OperatingSystem": "Mac OS X 10.15.7", "ExecutionsPerSecond": 145328.96875, "TestName": "Array.from(new Set(somearray))" }, { "RawUAString": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", "Browser": "Chrome 124", "DevicePlatform": "Desktop", "OperatingSystem": "Mac OS X 10.15.7", "ExecutionsPerSecond": 53622.11328125, "TestName": "_uniq(a)" } ] ``` The latest benchmark result shows that `Array.from(new Set(somearray))` is approximately 27x faster than `_uniq(a)` on the specified machine. Please let me know if this solution meets your requirements or if you need further clarification.
Related benchmarks:
Lodash union vs. ES6 Set
lodash vs un
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?