Skip to content

Arrays have low performance #1624

Answered by lahma
biwa asked this question in Q&A
Aug 27, 2023 · 2 comments · 3 replies
Discussion options

You must be logged in to vote

Here's a version of the sample written with performance in mind.

class Point
{
    constructor(x, y, z)
    {
        this.x = x;
        this.y = y;
        this.z = z;
   }
}

// Generate lots of points with random-ish x, y, and z values
const lookup = new Set();
const allPoints = [];
for(let i=0; i < 20000; i++) {
const point = new Point(random.next(25), random.next(25), random.next(25));
    allPoints.push(point);
}

const uniquePoints = [];

const start = new Date();

// Go through all points and add it to the list of unique points if the x, y, and z
// values have not been seen before
allPoints.forEach(p => {
    const key = p.x + '-' + p.y + '-' + p.z;
    if (!lookup.has(key)) {

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@lahma
Comment options

lahma Aug 27, 2023
Collaborator

@biwa
Comment options

Comment options

You must be logged in to vote
1 reply
@biwa
Comment options

Answer selected by biwa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1623 on August 27, 2023 15:04.