This Lesson Taught Me How To Do Better Benchmarks

  Рет қаралды 67,907

ThePrimeagen

ThePrimeagen

Күн бұрын

Пікірлер: 330
@McMurchie
@McMurchie Жыл бұрын
Neighbour: "Why doesn't your son go out and enjoy the sunlight?" Parent: "Because my son is working on code that will change the world" The son: "My left-pad shoots the fastest blanks in the west"
@godDIEmanLIVE
@godDIEmanLIVE Жыл бұрын
xDDD
@Sami_K99
@Sami_K99 Жыл бұрын
The lengths this man went to to prove he's right 😂
@briggsmiller7095
@briggsmiller7095 Жыл бұрын
Science!
@hotrodhunk7389
@hotrodhunk7389 Жыл бұрын
When you know you're right! 😂
@BrianBarrett0214
@BrianBarrett0214 Жыл бұрын
Just so his wife doesn't think he's a failure
@Soul-Burn
@Soul-Burn Жыл бұрын
Lengths which are powers of two!
@Jmcgee1125
@Jmcgee1125 Жыл бұрын
The ultimate way to prove you were only slightly slower than everyone else is to spend 36 hours sending 50 million requests.
@TheFelipe10848
@TheFelipe10848 Жыл бұрын
The chad never admits defeat 🗿
@programmer1356
@programmer1356 Жыл бұрын
To please the Wifeagen
@dipanjanghosal1662
@dipanjanghosal1662 Жыл бұрын
@@programmer1356 lmao TheWifeagen!
@scheimong
@scheimong Жыл бұрын
SPEND 36 HOURS SENDING DEEZ NUTS
@shawnington
@shawnington Жыл бұрын
@@scheimong I hope he rolled a server in Ligmu
@adrianorocha-dev
@adrianorocha-dev Жыл бұрын
Next competition should be about the most efficient way to measure dicts
@DarrenJohn10X
@DarrenJohn10X Жыл бұрын
Hard to beat this joke. 👏
@TheNewton
@TheNewton Жыл бұрын
HEARTY Cackling Chuckle in public.
@earthling_parth
@earthling_parth Жыл бұрын
I think it's already proven that middle out is the most efficient way to measure as well as _blow_ the dicts
@filiformis
@filiformis Жыл бұрын
@5:10 "stick with vendor implemented options and you will mostly get the best performance" Reminds me of the joke "How do you write faster Python? Use C."
@Impatient_Ape
@Impatient_Ape Жыл бұрын
@ThePrimeagen Bravo! Good to see you addressing the reality of environmental factors on timing benchmarks. With my background in large-scale scientific computing on shared resources, it was the first thing I thought of when I saw you discover (on Twitch) that your live-coded leftpad was "slower". The unpredictability is real. And it's frakkin' annoying.
@ThePrimeagen
@ThePrimeagen Жыл бұрын
Very frustrating
@excelfan85
@excelfan85 Жыл бұрын
I Also happen to be a scientist doing the science and math is cool especially when it proves things with charts. Id like to see more videos of whose chart is the fastest please
@paulosantana9607
@paulosantana9607 Жыл бұрын
4:44 well, ackshually, Strager posted a video here on yt where he absolutely destroys cpp and rust's native hashtable speeds by implementing his own hashing function. Of course it was designed for his specific use case, but I think it should be noted that the real take away of this are the friends we made along the way.
@marcusmors8485
@marcusmors8485 Жыл бұрын
that video was crazy, every time he increased the number of consults per seconds you would say "that's hard or impossible to improve" then he proves you wrong and repeat for 10 min more.
@torphedo6286
@torphedo6286 Жыл бұрын
well he means in the context of web, C++ is different.
@isodoubIet
@isodoubIet Жыл бұрын
" destroys cpp and rust's native hashtable speeds" I don't know about Rust but std::unordered_map is well known to be garbage
@andrejsk6211
@andrejsk6211 Жыл бұрын
@@isodoubIet Rust uses a cryptographically safe hashing function by default, but I believe you can give it a different one.
@isodoubIet
@isodoubIet Жыл бұрын
@@andrejsk6211 You can also give a different hash function to std::unordered_map, but that's not why it's terrible. The reason is that, in order to prevent iterator invalidation, they made it so that each entry in the hash map points to a linked list containing all the values. That all but guarantees a cache miss on every access, and it's too late to fix. Everyone needing an actual hash table in any context where performance matters will probably use the boost or abseil versions.
@blackfrog1534
@blackfrog1534 Жыл бұрын
hahahaha, the comment "this cured my impostor syndrome" has me dying lollll
@remirth_bergström
@remirth_bergström Жыл бұрын
This reminds me of that time TechSavvyTravvy beat Prime at leftPad.
@alter1eitay
@alter1eitay Жыл бұрын
you should definitely do more videos like this, they are fun to watch and helps to understand who to become a batter developer
@SandraWantsCoke
@SandraWantsCoke Жыл бұрын
yeah he's the BAST
@BulbaWarrior
@BulbaWarrior Жыл бұрын
In case you are curious, leftpadTravvy doubles the size of padding on every iteration, this means that only O(log(n)) string additions is performed. Although I have no idea why it is better to do it this way instead of adding a string of a given length right away. This technique is quite cool because it can be used in various domains, for example to raise numbers to a power of n quickly
@BulbaWarrior
@BulbaWarrior Жыл бұрын
Ah, silly of me to jump to the comments without actually finishing the video
@jakeysnaketube
@jakeysnaketube Жыл бұрын
yeah I stopped to work it out too, it’s neat!
@tylerfusco7495
@tylerfusco7495 Жыл бұрын
Nah because the second I saw that algorithm i’m like “oh shit that’s fast pow!” and immediately knew what it was doing, just from that one dumb bit shift (fast-pow video (TW: python) kzbin.info/www/bejne/faOxe3hspMysh7c)
@sebsplatter914
@sebsplatter914 Жыл бұрын
Haha same, stopped the video, got pen and paper, opened the mdn documentation for & and >>= and started working out each line. This is how I imagine C-programmers work all day (probably not, I assume this level of functionality has been optimized to all hell and back by people much smarter than me in the last ~50 years)
@eruryuzaki6505
@eruryuzaki6505 Жыл бұрын
"adding a string of a given length right away"? Because the number of chars is usually only known at runtime. So there is no string of a given length right away :D
@FinalSentinel
@FinalSentinel Жыл бұрын
Love this full on demonstration of what Prime means when he says mucrobenchmarks lie. Also love that he used the average of medians instead of the average of averages, this man how to measure anything’s. Sending all the signals for more of this.
@CaryKelnhofer
@CaryKelnhofer Жыл бұрын
Great video dude, would love to see more videos like this that focus around benchmarking. I really liked your benchmark videos you were doing awhile back with Rust vs TS vs Go. Another thing i'd like to see a video on, is some parsing code to an AST with rust. I've done a good bit of it with babel or jscodeshift, but it feels like another world when i'm trying to do it in Rust. Thanks again dude for all your hard work and long hours put into this stuff.
@EmberHext
@EmberHext Жыл бұрын
I respect going this hard about anything. On the other hand, I love weird incantations. Good shit Prime.
@EmberHext
@EmberHext Жыл бұрын
Also I've come to understand V8 a lot more since this event and still have more to go. I cannot recommend trying it.
@Redoxeon
@Redoxeon Жыл бұрын
Imposter syndrome left uncured
@ThePrimeagen
@ThePrimeagen Жыл бұрын
My goal is to make sure everyone feels like they have imposter syndrome
@Havirgem
@Havirgem Жыл бұрын
"All benchmarks are wrong, but some are useful."
@turun_ambartanen
@turun_ambartanen Жыл бұрын
No Errorbars/Standard deviations though. Can't really judge the data without them.
@alexandersemionov5790
@alexandersemionov5790 Жыл бұрын
Thank goodness you're coder, that ego was directed into the right place
@sebsplatter914
@sebsplatter914 Жыл бұрын
I like how much JS-Fuckery the Travvy solution managed to build in their. Hats off, I genuinely feel like I learned something just from figuring out why its so damn fast
@jasonfahnestock9494
@jasonfahnestock9494 Жыл бұрын
The classic linux book called Rebel Code by Glyn Moody contains a chapter on "lies and benchmarks". Statistics and benchmarks very often are misused or abused for propaganda and marketing purposes.
@martinandersson8544
@martinandersson8544 Жыл бұрын
You're not a failure to me Prime! Keep em coming. HOT video.
@Sakrosankt-Bierstube
@Sakrosankt-Bierstube Жыл бұрын
5:20 dude... i.. have no idea what's happening in the code.. and i am programming since i am 15...
@thingsiplay
@thingsiplay Жыл бұрын
I had to check if the video was running at x1.25 speed by accident.
@Drillgon
@Drillgon Жыл бұрын
This sort of power of two algorithm is really common in cryptography code where you have to do things like modular exponentiation. I think they actually use even wackier versions there with windows for doing multiple bits at once, I'd have to go read a crypto library again to be sure.
@thesaintseiya
@thesaintseiya Жыл бұрын
Let's goo finally more second channel uploads
@verrigo
@verrigo Жыл бұрын
Signal. More of this please. This is gold content
@froozynoobfan
@froozynoobfan Жыл бұрын
Making the internet better one function at a time, this is great!
@antronixful
@antronixful Жыл бұрын
the only thing that matters here is that he proved that people doesn't understand basic statistics... what a great dude
@MrHords
@MrHords Жыл бұрын
Loving the vids Prime! I stumbled upon your videos a few months ago and now I'm watching every one of them. You've inspired me to try and learn rust as well and coming from Python/Golang I feel like I'm going to get destroyed but at least I'll be able to write code that can run on literally anything!!
@ammaryasser1391
@ammaryasser1391 Жыл бұрын
Classic Prime video, keep it up my man
@somniad
@somniad Жыл бұрын
Median is a weird metric - it captures an idea like "a normal run" but doesn't capture the data's skew unless the distribution of the differences from the median are symmetric, in which case the median is the same as the average because it has no skew. So, does it?
@ThePrimeagen
@ThePrimeagen Жыл бұрын
The median tends to be a lot better in these cases. Especially when it comes to the internet's. At least that is my general experience with things. But everyone has their favorite way of doing things.
@derschutz4737
@derschutz4737 Жыл бұрын
It def isn't the ideal way (line charts/histograms). But it probably doesn't matter because the variability/spread is so low.
@UnhingedNW
@UnhingedNW Жыл бұрын
GREAT VIDEO SO GLAD YOU ARE BACK TO POSTING HERE
@AndréTomás-d8e
@AndréTomás-d8e Жыл бұрын
I guess imposter syndrome is back on the menu
@hagnap
@hagnap Жыл бұрын
I like this type of content. It makes me feel as smart as Tom
@GrantGryczan
@GrantGryczan Жыл бұрын
Exponential string concatenation is faster because it's O(log(n))! It only has to iterate over the number's bits.
@titusmoore1530
@titusmoore1530 Жыл бұрын
Toms a genius!
@zekicay
@zekicay Жыл бұрын
travvy's solution is the fastest because it does at most 2*log(N) + 1 concatenations and half of them are destructive.
@EmberHext
@EmberHext Жыл бұрын
It's identical to how the string.repeat (used in the one I posted) and string.padStart built-in functions work in terms of their logic. Mine's slightly slower using .repeat because there's some overhead in the process of using that over the native, but his is effectively identical in performance to the native because they're doing the same thing without that overhead.
@erickmoya1401
@erickmoya1401 Жыл бұрын
Isnt the "standard" solution also (possibly) different, because it depends on the implementation each interpreter has? Or am I missing something?
@bloody_albatross
@bloody_albatross Жыл бұрын
These days people think V8 is the only JavaScript engine there is, so that thought doesn't even occur to them.
@wtcxdm
@wtcxdm Жыл бұрын
We really need to shout "Charts!!" like Prime did at 03:30 when present in corp
@Yupppi
@Yupppi Жыл бұрын
I'm thinking would calculating standard deviation also give insight on the algorithms? Is it possible some have inherently more variance than others but it gets hidden when you shrink the results to average of medians? Like perhaps you prefer just slightly slower algorithm if the worst case scenarios are not nearly as bad. I don't know how to interpret the statistics in this sense.
@aziz0x00
@aziz0x00 Жыл бұрын
Really great, I love that power of two algorithm and that you mentioned String.repeat does it!
@antonbeng
@antonbeng Жыл бұрын
I'm at work primeagen, you can't be that funny at the end 😂
@anonlegion9096
@anonlegion9096 Жыл бұрын
3:05 why apache?
@levabala4922
@levabala4922 Жыл бұрын
would love to see proportional difference in results between micro and linode(c) benchmarks to see how much does actually microbenchmarks LIE :3
@RagTagPwner
@RagTagPwner Жыл бұрын
It's 8am and my brain isn't on yet, but this was good to hear, so here's some algo juice as requested.
@jimothyus
@jimothyus Жыл бұрын
Well this isnt really fair to prime he wrote that thing in 2 seconds on a livestream, im sure the twitter fellas did a few iterations before publishing their results
@ThePrimeagen
@ThePrimeagen Жыл бұрын
He actually checked out the internal implementation of V8 string Repeat
@franekborowiec9648
@franekborowiec9648 Жыл бұрын
let's goo finally another yt vid from my fav youtuber
@hironichu
@hironichu Жыл бұрын
This was very instructive on why we shouldnt re-re-re-invent the wheel, though I am in favor of trying to re-invent the wheel to understand how some mechanics works, to learn new stuff, but at the end we should stick to what has been done and been proven to be functionnal and fast !
@TheNewton
@TheNewton Жыл бұрын
Yes , use ready made wheels to build spaceships. It's why leftpad caught so many off guard because downstream vendors of important material aren't given a thought , or more importantly a single dime.
@russellwaterhouse502
@russellwaterhouse502 Жыл бұрын
Would love to see a video going into depth about how to apply these techniques to other problems.
@mattwilly7959
@mattwilly7959 Жыл бұрын
I really enjoy how you can make more complicated topics fun
@thorbergson
@thorbergson Жыл бұрын
That's why I like Prime, he is not afraid to be wrong, not afraid to admit that he was wrong, and has the skill to get to the bottom of the issue. Would be even more terrific if the method was explained in more detail (why medians, why sum etc), but probably his disappointing stats on longer videos mean he's forever skewing towards "funner", more dynamic, less involved, style.
@Kavukamari
@Kavukamari Жыл бұрын
Isn't power of two string concatenation faster because the rope data structure is a binary tree?
@DuongLe-em4dg
@DuongLe-em4dg Жыл бұрын
The left pad incident. I didn't know it was a thing since Prime rewrite left pad and it become a trend kekw
@dungeon4971
@dungeon4971 Жыл бұрын
ok but I still don't get why primes implementation was slower in the micro benchmarks was it garbage collection boosting the result for the original if so why or rather how, is using requests and manually trigger garbage collection the best way, what would happen if manual garbage collection was turned off, would be see that all the results would be randomized, would change the order of these test change the result, would prime's solution still win ? this video leaves me with more questions than it answers
@sillysquirrel9979
@sillysquirrel9979 Жыл бұрын
THIS IS A MARKER! Flip nice editing btw
@petrpechkurov3095
@petrpechkurov3095 Жыл бұрын
Thank you, Mr. ThePrimeagen!
@Tantewillieja
@Tantewillieja Жыл бұрын
Glad your back on the main channel!
@danielvaughn4551
@danielvaughn4551 Жыл бұрын
I want to see an explanation video by whoever the f wrote that leftpadTravvy implementation. I've been writing JS for a decade and I have absolutely no idea what he was doing.
@johnellis4569
@johnellis4569 Жыл бұрын
blazingly fast 🤩
@clo4
@clo4 Жыл бұрын
While watching this my partner said “this guy sounds like Gru” and now I can’t unhear it
@TheAriznPremium
@TheAriznPremium Жыл бұрын
so if i have a slow benchmark, i should change the way i benchmark to make it faster, i see /s
@zeekcom12
@zeekcom12 Жыл бұрын
how do you learn the deeper stuff of js? What search terms or black wizard do I have to consult
@failscript
@failscript Жыл бұрын
Nice, my shit talking comment made it into the video 😂 sorry Prime! And thank you for going an extra mile to enlighten us
@u9vata
@u9vata Жыл бұрын
Microbenchmarks are totally not misleading in most cases if you benchmark your own data structure / algorithm with no unknown magic... Like strings as weird trees and stuff are unknown magic - but GC is the biggest unknown magic among all... Of course even then a microbench might be misleading a bit - like maybe an algorithm uses more memory (and thus also more cache), but is faster. When alone... It however incurs the extra memory cost for example - but this is well understood and it always amazes me how hard is to benchmark something in a managed / gc language properly.....
@etch-6261
@etch-6261 Жыл бұрын
i never thought of this, is putting everything on a server the only solution?
@trash_dev
@trash_dev Жыл бұрын
benchmark deez 🥜
@DrIngo1980
@DrIngo1980 Жыл бұрын
Whoever is your editor, pay them more. They earned it with this one.
@flipmediaprod
@flipmediaprod Жыл бұрын
Appreciate you bro🙏
@slomellos
@slomellos Жыл бұрын
There is an extention called ' Blazingly™ ' which replaces words like blazing or blazingly with Blazingly ™
@okskaren
@okskaren Жыл бұрын
More of this prime!! Love from brasil
@ambuj.k
@ambuj.k Жыл бұрын
The only reason for the leftPad node package to exist was until it was actually implemented by node js std string type.
@feeelix
@feeelix Жыл бұрын
This is truly one of the moments of all time
@bigbodge
@bigbodge Жыл бұрын
is native blazing fast tho?
@dorskCSGO
@dorskCSGO Жыл бұрын
this is the stupid thing i do so u know that this is the type of video i like... thx for the content!
@yeahaddigirl
@yeahaddigirl Жыл бұрын
Listen man, the last time I stuck to vendor implementations I got a new gamepad instance from navigator every frame I held an input down in my electron app.
@bloody_albatross
@bloody_albatross Жыл бұрын
Was there a submission that used the classical version? function leftPad(str, len, ch) { var strlen = str.length; return len > strlen ? new Array(len - strlen).join(ch || ' ') + str : str; } That's what people used before there was .padStart() or .repeat().
@boiadeiro8272
@boiadeiro8272 Жыл бұрын
I knew there is something wrong with the measuring by the time differentials
@avi7278
@avi7278 Жыл бұрын
Hey Prime are you okay with people stealing your content and putting it on KZbin?
@AloisMahdal
@AloisMahdal Жыл бұрын
3:10, ooh, a never-nester, huh? 😀
@BonerPauler
@BonerPauler Жыл бұрын
i understood nothing but i wish i was able to talk nerdy like you
@abbashaider7165
@abbashaider7165 Жыл бұрын
Whyyy does he do charts on spreadsheets and not python? I mean whyyy?? Am I missing something
@alexandrep4913
@alexandrep4913 Жыл бұрын
You really got em. You did it bro.
@sweetdreamsdotexe
@sweetdreamsdotexe Жыл бұрын
What a character development arch.
@Kavukamari
@Kavukamari Жыл бұрын
Mike Rowe does benchmarks?
@a_maxed_out_handle_of_30_chars
@a_maxed_out_handle_of_30_chars Жыл бұрын
but what is leftpad?
@AdiosOcelote
@AdiosOcelote Жыл бұрын
Have a comment to my like so that the YT magic happens, you know. Be healthy.
@AJRepp
@AJRepp Жыл бұрын
Ok but what about inlining some wasm how would that go.
@Pedro-jj7gp
@Pedro-jj7gp Жыл бұрын
I've been watching your videos for a while now, so entertaining! I'm not really into web dev and do mostly low-level, but you've got me interested. What would you recommend to get started with backend and rust? And is it ok if I skip javascript for that matter?
@KrakonosovoBabka
@KrakonosovoBabka Жыл бұрын
You have to skip js, it is evil.
@aro_matt
@aro_matt Жыл бұрын
doing the stupid thing in good faith! Appreciate you man! :)
@prerit714
@prerit714 Жыл бұрын
Thats why we love you prime
@thineshgen
@thineshgen Жыл бұрын
Need more of these sorts of code analysis of your piers..Plz
@GetAnAndroid
@GetAnAndroid Жыл бұрын
Love the video Also protobuf video when
@zaneearldufour
@zaneearldufour Жыл бұрын
Don't be a failure! Great video :)
@Oaisus
@Oaisus Жыл бұрын
What I'm hearing is that javascript has weird strings and this microbenchmark would work fine in a real programming language like C++
@brendanhansknecht4650
@brendanhansknecht4650 Жыл бұрын
Why the average of medians? Why not the global median or something else?
@InvisibleManCZ
@InvisibleManCZ Жыл бұрын
I highly favour your efforts of diving deep into nitty gritty. It can inspire a lot.
@mateusstanki
@mateusstanki Жыл бұрын
Javascript doesn't have tail recursion optimization...
@SebbeSober
@SebbeSober Жыл бұрын
you're currently my favorite youtuber
@SebbeSober
@SebbeSober Жыл бұрын
i would actually say favorite person in the world but it seems a bit too much 🙄
@seiIaeu
@seiIaeu Жыл бұрын
Would be very nice a video about performance bottlenecks and how tools that measure function call and whatever can be misleading
@corneliussawatzky3887
@corneliussawatzky3887 Жыл бұрын
"use native", does this law/principle of superior workmanship translate to app development like tauri/flutter against swiftui?
@daveisradicle
@daveisradicle Жыл бұрын
ofc course the ever savvy travvy nailed it
This Algorithm is 1,606,240% FASTER
13:31
ThePrimeagen
Рет қаралды 859 М.
Is JSON Blazingly Fast or...?
9:57
ThePrimeagen
Рет қаралды 197 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
Dramatically improve website speed with Partytown
3:39
Beyond Fireship
Рет қаралды 178 М.
zig will change programming forever
9:34
Low Level
Рет қаралды 364 М.
Dioxus vs Leptos  | Rust GUI Wars #2
21:18
Creative Coders
Рет қаралды 12 М.
Rust Foundation IS DOING WHAT????
8:17
ThePrimeagen
Рет қаралды 339 М.
How I Made JavaScript BLAZINGLY FAST
10:10
ThePrimeagen
Рет қаралды 224 М.
I Went To DEFCON!
16:25
ThePrimeagen
Рет қаралды 328 М.
Why i think C++ is better than rust
32:48
ThePrimeTime
Рет қаралды 339 М.
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,8 МЛН
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,6 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19