Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
unique coordinates
(version: 0)
Comparing performance of:
Array from - Set vs For loops
Created:
8 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var coordinates = []; for (var i=0; i< 5000; i++) { coordinates.push(Math.round((Math.random()*360-180)*1e7)/1e7, Math.round((Math.random()*360-180)*1e7)/1e7) }
Tests:
Array from - Set
var unique = Array.from(new Set(coordinates.reduce((r, a, i) => (i % 2 ? r[r.length - 1].push(a) : r.push([a]), r), []).map(a => a.join('|'))), s => s.split('|').map(Number));
For loops
var temp = []; var unique = []; var uniqueCoords = []; for (var i = 0; i < coordinates.length; i += 2) { temp.push(coordinates[i] + '|' + coordinates[i + 1]); // create some strings } for (var i = 0; i < temp.length; i++) { if (unique.indexOf(temp[i]) === -1) { unique.push(temp[i]); uniqueCoords.push(temp[i].split('|')) } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Array from - Set
For loops
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!
Related benchmarks:
unique coordinates
unique coordinates
unique coordinates
unique coordinates
Comments
Confirm delete:
Do you really want to delete benchmark?