this post was submitted on 30 Jan 2025
962 points (99.7% liked)

memes

14521 readers
3937 users here now

Community rules

1. Be civilNo trolling, bigotry or other insulting / annoying behaviour

2. No politicsThis is non-politics community. For political memes please go to !politicalmemes@lemmy.world

3. No recent repostsCheck for reposts when posting a meme, you can only repost after 1 month

4. No botsNo bots without the express approval of the mods or the admins

5. No Spam/AdsNo advertisements or spam. This is an instance rule and the only way to live.

A collection of some classic Lemmy memes for your enjoyment

Sister communities

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] manucode@infosec.pub 58 points 3 months ago (4 children)
[–] wise_pancake@lemmy.ca 39 points 3 months ago (1 children)

I have a great performance optimization for this

What if instead of 1s sleep, we did 0.5s sleep? That’s a 100% improvement.

[–] Amanduh@lemm.ee 15 points 3 months ago (3 children)

It's not sleeping for 1 second, $1 is an input parameter in the script

[–] wise_pancake@lemmy.ca 4 points 3 months ago

That sounds expensive

[–] JackbyDev@programming.dev 2 points 3 months ago (2 children)

I took it as meaning sleep for a number of seconds equal to half the value you're sorting. So like f "(( $1 / 2 ))" & or however math works in bash, I always forget.

[–] Amanduh@lemm.ee 1 points 3 months ago (1 children)
[–] JackbyDev@programming.dev 2 points 3 months ago (1 children)
[–] Amanduh@lemm.ee 1 points 3 months ago (2 children)

I bet you also tell people you love regex because you think it makes you look smarter lol

[–] jollyrogue@lemmy.ml 2 points 3 months ago (1 children)

What if you do love regex? 🥺

[–] Amanduh@lemm.ee 1 points 3 months ago (1 children)

Then you should be cast into the fires of Mt doom where you belong

[–] jollyrogue@lemmy.ml 1 points 3 months ago (1 children)

You wouldn’t say that if you knew regex. 😆

[–] Amanduh@lemm.ee 1 points 3 months ago (1 children)

Programmers and being smug assholes, name a more iconic duo

[–] jollyrogue@lemmy.ml 1 points 3 months ago

Project much?

I’ll play though.

Amanduh being a humorless chore. 😁

[–] JackbyDev@programming.dev 2 points 3 months ago (1 children)

Well, maybe not with regex, but I'd be lying if I said I never get satisfaction things like that lol. Bash and regex both are very useful tools, great at what they do, but have some design choices that make them annoying. That's sort of what I was trying to get at by saying "yes but also skill issue" lol. A good example is iterating over output in bash. I have zero confidence it's going to do anything remotely close to what I want and have to look up stuff every time I'm trying to do it. "Is it going to go word by word? Line by line? Are there null byte separators?" PowerShell seems appealing in that regard because it works with objects instead of text, but I haven't really used it in depth and I don't see myself going through it just to see if it's worth trying to use more often.

[–] Amanduh@lemm.ee 0 points 3 months ago

Cool story bro

[–] lurch@sh.itjust.works 1 points 3 months ago

Fractional math doesn't happen in bash, but bc can be called and sleep can take fractions as parameters.

[–] lurch@sh.itjust.works 0 points 3 months ago (1 children)

the idea isn't wrong tho, as sleep can do fractions. bash cannot though. therefore it would bloat the code a bit to use bc to multiply the parameter by 0.5 or so.

[–] Amanduh@lemm.ee 1 points 3 months ago

It isn't what is happening though lol...

[–] devfuuu@lemmy.world 10 points 3 months ago

For anyone who controls time travel this is the fastest algorithm ever. Probably gonna change everything when we are traveling through space and passing by some dark holes.

[–] morrowind@lemmy.ml 1 points 3 months ago

Even as a joke, this doesn't avoid anything. The system scheduler just has to do the sorting using a regular algorithm

[–] idunnololz@lemmy.world 1 points 3 months ago (1 children)

The output isn't guaranteed to be correct though. Most implementations of sleep can only guarantee that it will sleep for at least the amount of time specified. It can sleep for longer though.

[–] JackbyDev@programming.dev 4 points 3 months ago

I remember seeing discussions about this at the time, it would also sometimes fail with a very large number of 1s and a single 2.