r/learnjavascript • • May 14 '21

Remove Duplicate Value from array

Post image
234 Upvotes

89 comments sorted by

View all comments

Show parent comments

-3

u/StoneCypher May 14 '21

A fourth time, I'm requesting that you provide the perf you claim to have written

2

u/[deleted] May 14 '21

Here i've modified someone else's that you seemed to be interested in, now where's your wonderful implementation?

https://www.reddit.com/r/learnjavascript/comments/nc6i5j/remove_duplicate_value_from_array/gy48wl4?utm_source=share&utm_medium=web2x&context=3

0

u/StoneCypher May 14 '21

That's not a perf. That's you copy pasting someone else's output

Is it fair to suggest that the work you're standing on having done is just you attempting to guess from someone else's work?

 

now where's your wonderful implementation?

Why are you asking? Is it because you believe claiming to have done a perf, then not having done one, is a problem?

Looks like the comment you're responding to is deleted.

Is it a problem that their output is copy pasted from StackOverflow, that you're claiming you did, and that the StackOverflow post is about something else?

3

u/[deleted] May 14 '21 edited May 14 '21

You clearly didn't even read my comment. I said that I took their test, which you were a big fan of btw, you just didn't like the number in the loop, and corrected the clear bugs (which you didn't notice, maybe you're not as smart as you act?), and ran it locally.

~/perf
❯ ls
indexOf.js set.js

So I split their code into two files, just like i said in the comment you ignored.

Here's the contents, largely unmodified - just moved the timing code around. running it on much bigger numbers than 10_000 will be slow af because of the dumb way they were building the array. But at merely 10_000 * 7 items we already have a clear winner.

~/perf
❯ cat indexOf.js
const {
    performance,
} = require('perf_hooks');

const template = ['✅', '✅', '❌', '👹', '😉', '🤯', '🤯'];
let emojis = [];

for (let i = 0; i < 10_000; i++) {
    emojis = emojis.concat(template);
}

// const setStart = performance.now();
// const deDupe = [...new Set(emojis)];
// const setEnd = performance.now();
// console.log('Took', (setEnd - setStart).toFixed(4), 'milliseconds to generate:');

const filterStart = performance.now();
const deDupe2 = emojis.filter((value, index) => emojis.indexOf(value) === index);
const filterEnd = performance.now();
console.log('Took', (filterEnd - filterStart).toFixed(4), 'milliseconds to generate:');

~/perf
❯ cat set.js
const {
    performance,
} = require('perf_hooks');

const template = ['✅', '✅', '❌', '👹', '😉', '🤯', '🤯'];
let emojis = [];

for (let i = 0; i < 10_000; i++) {
    emojis = emojis.concat(template);
}

const setStart = performance.now();
const deDupe = [...new Set(emojis)];
const setEnd = performance.now();
console.log('Took', (setEnd - setStart).toFixed(4), 'milliseconds to generate:');

// const filterStart = performance.now();
// const deDupe2 = emojis.filter((value, index) => emojis.indexOf(value) === index);
// const filterEnd = performance.now();
// console.log('Took', (filterEnd - filterStart).toFixed(4), 'milliseconds to generate:');

and just to prevent you from whining about the length, i modified the array filling and ran with 70 Million items, and added lodash for fun

~/perf
❯ node indexOf.js
Took 716.0615 ms to build array
Took 257.2369 milliseconds to dedupe

~/perf
❯ node set.js
Took 716.1850 ms to build array
Took 177.0432 milliseconds to dedupe

~/perf
❯ node lodash.js
Took 704.8663 ms to build array
Took 175.9701 milliseconds to dedupe

Ok, your turn.

-1

u/StoneCypher May 14 '21

This isn't a perf, and these numbers contradict the claims you made earlier.

In some ways this is actually better than a perf - it uses performance.now, after all - but also it's statistically poorly controlled, and re-running it causes serious variance, and you have nothing even resembling a matrix

You also seem to be assuming that what's true on your computer, under just node, under one version, on your operating system, is true for all machines.

That's quite odd, from someone who insisted that this was "implementation defined." Now you seem to only be testing one implementation, and insisting that's correct.

You seem, in fact, to be falling afoul of your own original criticism, in the single most gruesome possible way

What do you think "implementation defined" as a criticism actually means?

What do you think is the difference between a perf, and just measuring your machine's clock?

 

and corrected the clear bugs (which you didn't notice, maybe you're not as smart as you act?)

So if I don't pay close attention to the work that you hadn't given me, I'm low intelligence?

Jesus. I'd better learn to be psychic fast, huh? 😂

 

But at merely 10_000 * 7 items we already have a clear winner.

Looks like you are skipping the other one, which was the one I was skeptical about

"Gee I wonder why"

Funny how one of the three methods you claimed to have tested in code you claimed to have written is now disappeared in what you've provided after you were asked five times and pretended to have had it all along

 

running it on much bigger numbers than 10_000 will be slow af

I dunno, this conversation is several hours longer than the doing it right part would have been

 

and just to prevent you from whining

This is whining

 

i modified the array filling

so after you explained that this was why you didn't do it right, you ... fixed it, and did it right

okay 😂

 

and added lodash for fun

Note that:

  1. Adding lodash produced more complicated code

  2. Adding lodash produced code where the questions I asked you, that you still haven't answered, now can't be answered, whereas they easily could be with the normal approach

  3. You don't seem to be willing (or possibly able?) to answer my questions

  4. Yes, I saw that you said you disagreed with CERT about the severity of those bugs. That's quaint. Do you expect that to be folded in?

1

u/[deleted] May 15 '21

Please for the fucking love of god stop typing walls of text that are barely related to anything relevant. I've run a fucking marathon keeping up with your moving goal posts, and you've still yet to provide your implementation.

I took someone else's benchmark that you approved of minus one thing, changed that thing to your liking, removed the bugs you missed and focused the timing on the actual task, and now you are saying it's not valid.

But since it's showing the Set approach is faster you have a problem with it. You already said earlier you wrote your own benchmark. So let's see it. It better be running on every fucking runtime and class of machine you know of after your latest bitching.

But of course you won't. Let me to repeat this, forgetting the benchmark you already wrote for a moment, you have still yet to provide even your implementation. That's because you don't have one that's an actual improvement of the image in the original post. It's vapor. You're a blowhard.

2

u/rGustave77 May 15 '21

Yeah I'm honestly waiting for him to "prove himself right" like he has said earlier. I'm not even biased in this discussion I just want the numbers

2

u/[deleted] May 15 '21

There's no way using indexOf inside a loop is going to be faster than using a Set as the array grows past a certain point, he's full of shit. My original point was that maybe using a plain object would be faster than Set, but that would depend on the runtime and how new Set() vs {} is handled - aka an implementation detail

1

u/[deleted] May 16 '21

u/StoneCypher never replied, because he's stupid and wrong, and everyone lived happily ever after. The end.

1

u/takert541 May 15 '21

the dafuq dude. those are 4 pages of lines which you can otherwise spent on your job and be more productive lol

1

u/[deleted] May 15 '21

You are in the correct good sir(I believe). But both of you got your knickers all twisted in each others’ business.

Gut instinct says your right: have done zero tests. Will confirm if I end up feeling like it :) or better arguments (any) are given to why you are wrong...

Chances are your tone/diction is the reason for the downvotes - it comes off as confrontational and petulant (if I put in my empathy lenses).

In any case: an entertaining read. I’d prefer you to get more upvotes as I think this is a useful discussion point.

1

u/StoneCypher May 15 '21

Chances are your tone/diction is the reason for the downvotes

Reddit is a herd, is the reason

1

u/[deleted] May 15 '21

Herd mentality signaled by many things: diction included. I point this out to aid. Signaling the herd is a skill.

0

u/StoneCypher May 15 '21

Evidence would make what you're trying to say to me compelling.

The evidence I've gathered over the years seems quite different: with moderate frequency I'll post the same thing word for word in the same thread twice, and end up with one at +50 and the other at -30, with no apparent difference other than what the early votes were

My belief is that people see orange and click up, or see blue and click down, without even reading the text

I see that you're attempting to instruct me on behavior, with the expectation that your guess-driven faith is factual

What you seem to have missed is that I don't actually care if I get downvoted. Internet points have no meaning to me.

Please take note of how many times I've requested that you explain this to me, or asked for your advice on my behavior, before offering it a third time.

"Diction" is how well someone pronounces a word, by the by. It doesn't emerge in typed text, and has nothing to do with their tone of voice or demeanor. Diction is what people work on if they stutter, or if they had a stroke and are slurring words.

 

Signaling the herd is a skill.

That's nice.

1

u/[deleted] May 15 '21 edited May 15 '21

Diction: the choice and use of words and phrases in speech or writing. ---first google result

Diction has a few meanings. I mean it in the sense of word choice.

Your believe is a take on the situation, and yes, I've experienced this random noise as well, but there's a noise floor (to borrow a concept of audio production)...

We are all just meat computers, I am trying not to instruct or overwrite - just offering information I think is relevant to you.

If you are giving good information: your internet points are relevant for parsing information on learning forums such as these to those other than yourself. I know I didn't I phrase that clearly, so try to be generous in your interpretation. My general point is - I want good information to rise to the top. I think you do to? (that I'm guessing on you not being a bad actor trying to suppress good information, and are human with a general desire to read good information) I haven't missed - I'm aware they aren't important to you, I'm suggesting that maybe a re-calibration might not be a bad idea.

Despite what I say, the reality of my world view is we are all meat computers trying to program each other to be and work for the world we want, so take what I have to say with a grain of salt :)

→ More replies (0)