The benchmarks should really also include memory allocations. array map/filter create new a new copy of the array every time so even if they look decent on isolated benchmarks they put load on the GC which may introduce lag spikes if you spam them too much.
@lbgstzockt849310 сағат бұрын
And memory reads. I would rather do ten compares than one RAM read.
@CTSSTCСағат бұрын
We should just transpile code and let it choose the best for loop :P maybe allow an annotation for expected loop size or even better let the runtime figure it out and optimize over time due to it running its own measurements ;D These are things we shouldn't be worried about when it could potentially be automated. We should instead be focused on conveying expectations.
@allesarfint7 сағат бұрын
0:24 "Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."
@AbdelhakOussaid15 сағат бұрын
Shout out to those developers, like me, who write gibberish and it works!
@ARandomUserOfThisWorld15 сағат бұрын
I don’t just use a DB… I use an excel spreadsheet, and when it runs of space(which is hardcoded at like 1mil rows), it creates a new spreadsheet with a new ID which is specified in the filename and nowhere else, and use that, all of those files together, instead of a DB. And all of them are .xlsx files btw.
@vikingthedude14 сағат бұрын
@@ARandomUserOfThisWorld awesome. I use fopen
@sad_man_no_talent14 сағат бұрын
@@ARandomUserOfThisWorld I just use a json file
@everythingisfine998813 сағат бұрын
💪👑
@Alfakatt13 сағат бұрын
Us
@cosmiclattemusic15 сағат бұрын
can't unsee NODE transitioning to DONE 😭
@k00lmoh13 сағат бұрын
you mean DENO
@orcagaming214312 сағат бұрын
No he means done but it'll be oden before it because done😊
@jackiedo73707 сағат бұрын
NODE -> DENO -> ODEN -> DONE 🎉
@erikjohnson911214 сағат бұрын
Quicksort is not a stable sort. With a stable sort routine equal items will have the same relative order compared to the original. Quicksort does not have this feature. Most of the time you might not care, but that IS a difference worth noting.
@dentjoener14 сағат бұрын
Thank you, and with sort getting faster on strings, it's probably trying to minimize comparisons, something TimSort does in Java and Python, because comparing is more expensive. Plus TimSort is stable.
@eliasepg10 сағат бұрын
7:52 "you're good enough even when you're not at your best" love this statement, very deep
@ErazerPT11 сағат бұрын
As pertains to the first example, repeat after me children : I shall NOT microbenchmark things where the function call overhead overshadows the work being done by an order of magnitude or more. Seriously, this is such a common thing it should be a meme for all intents and purposes. Now, show us a run where the work being done doesn't amount to "basically nothing at all", ie, something a tiny bit realistic...
@noirsociety15 сағат бұрын
"Languages that try to disallow idiocy become themselves idiotic." -- Rob Pike
@okie902513 сағат бұрын
sounds a lot like rust to me
@netssrmrz9 сағат бұрын
great quote. sounds like React to me.
@randomuser664389 сағат бұрын
@@okie9025Here they come
@shellderp8 сағат бұрын
The key point here is our programmers are Googlers, they’re not researchers. They’re typically, fairly young, fresh out of school, probably learned Java, maybe learned C or C++, probably learned Python. They’re not capable of understanding a brilliant language but we want to use them to build good software. So, the language that we give them has to be easy for them to understand and easy to adopt. It must be familiar, roughly C-like. Programmers working at Google are early in their careers and are most familiar with procedural languages, particularly from the C family. The need to get programmers productive quickly in a new language means that the language cannot be too radical. Actual Rob Pike quote
@kasper_57311 сағат бұрын
The most important thing to measure is the performance of your application, not your modules or functions. Measure those once you’ve detected a performance issue with your app, and need to drill down as to why and fix the issue. A slow sum or sort is usually pointless to optimize if its impact on your app is negligible.
@V3racious314 сағат бұрын
This Deno commerical brought to you by Deno.
@rawallon14 сағат бұрын
A Deno a day keeps the exception away
@johnvomberg45014 сағат бұрын
The introduction was the most interesting part of this video.
@k98killer5 сағат бұрын
Technically, there is a fifth way to loop: `for (let i=arr.length-1; i>=0; i--)` or `for (let i=0,l=arr.length; i
@jakeave15 сағат бұрын
We've been able to squeeze out more by declaring i before and not using a lookup for the length. I know it sounds terrible, but it's ever so slightly faster. let i = 0; const len = arr.length for (; i < len; i++) Use at your own peril.
@jerichaux921914 сағат бұрын
I've done similar. As long as you maintain ownership over the array (to ensure the length isn't suddenly shorter than it was when you'd began), this is fine.
@JasminUwU13 сағат бұрын
@@jerichaux9219 That sounds like an absolutely horrible bug to discover
@S7hadow13 сағат бұрын
I can see .length as having a slight overhead and so making a difference over a big number of loops. But the declaration of i doesn't seem logical to me as that part of the for loop is only run once. Guess I have to try Deno bench now
@rumfordc12 сағат бұрын
@@S7hadow i believe the declaration is because scoping rules for loops are different from the rest of the function in javascript. the interpreter also needs to differentiate between which type of for-loop it is, which the semi-colon disambiguates immediately as opposed to reading the entire declaration before knowing which type of loop the declaration is for.
@rumfordc12 сағат бұрын
also making that a while-loop should be faster than a for loop
@zeikjt4 сағат бұрын
8:02 Yes, yes, noooooo! Using something like Deno bench doesn't tell you where bottlenecks in your program are! You need to profile your actual code in-situ. Then if you prove there's a bottleneck somewhere and it is affecting the performance of your program in a meaningful way then you can use bench to try and find faster alternatives, but then you need to test it again in-situ to make sure it actually performs better. You might have misunderstood the shape of the data, or the shape of the traffic to your code and find that your speed up didn't actually change much. You can't always test these things accurately synthetically, and you won't know it until you try it with the real thing :)
@thepaintedsock2 сағат бұрын
Great video. The for loop can be sped up even more if you create the for(let i=0, len=arr.length; i < len; ++i)
@r5LgxTbQ10 сағат бұрын
5:20 no fair, your benchmark doesnt account for the compute power to create the Set in the first place. You're not starting from the same place so it's not an accurate comparison
@zeikjt4 сағат бұрын
Ideally you'd be using a Set from the get-go instead of an array, then you are starting from the same place. But if it's an all-at-once allocation instead of incremental then sure. This is why benchmarks are not ideal, test your real code to find actual bottlenecks and then you have the real situation.
@sahilaggarwal200415 сағат бұрын
The set example is not really accurate. Although I agree that it definitely provides performance benefits over Array.includes() in case of large data but while benchmarking we must also include the one time overhead taken to create the set as we are originally dealing with array data type.
@aleksander529814 сағат бұрын
that's why small array is faster than small set, but big set is faster than big array, you edgy boy
@Slackow14 сағат бұрын
@@aleksander5298 big set is only faster if you actually keep the set up to date, and use it for multiple times, if you remake the set every single time then it's slower.
@beyondfireship14 сағат бұрын
I disagree. The array is already in memory, so the Set should be too. The objective is to "find an element", not create the original data structure. One-time setup is insignificant on a task that runs millions of times. But just for fun, recreated the Set on each benchmark run and it still performed 20x faster.
@aleksander529813 сағат бұрын
@@Slackow why would you remake set lmao are you dumb? just use set instead of array, ez, you have skill issue or what?
@sahilaggarwal200413 сағат бұрын
@beyondfireship yeah that's what I said, set will be faster, no doubt in that. But the performance gain is not a million times faster if we consider the time to create the set too, and that's what I felt was inaccurate.
@patric_forreal3 сағат бұрын
Using the SET trick to sort is much like using hash map ✅
@lwinklly14 сағат бұрын
Anton mentioned 🎉
@MelroyvandenBerg8 сағат бұрын
Yes he was. I'm recently creating quite some PRs for his tests 😅
@Dominik-K15 сағат бұрын
Rob Pike mention ftw
@RandomGeometryDashStuff13 сағат бұрын
06:49 unfair test! `[69,420].toSorted()` result is `[420,69]` but other sort functions output is `[69,420]`
@mmanomad13 сағат бұрын
Love seeing more Deno videos!
@pirixyt12 сағат бұрын
You forgot to loop with a while loop.
@brandongregori9959 сағат бұрын
Probably the exact same as a for I loop
@M0du5Pwn3n57 сағат бұрын
It is worth saying: Knuth was talking about fiddling with bits in assembly. He was NOT talking about writing your programs in a basically performant way. He was CERTAINLY not saying "don't think about performance at all until later". Rob Pike's rules assume that you are writing your program in a sane way already, rather than in dog-slow nightmare spaghetti. There is a reason that Go is designed the way it is - it's not because all organizations of your program are equally valid and the structure doesn't matter until the end when you measure it. If you write your code in an inherently slow way, then once you measure it, it is too late. When you go to measure it, you will discover that there is no particularly expensive part you can optimize because the entire thing is sludge. Also, quicksort is not a fancy algorithm. It is known and extremely easy to copy. If you are not confident about your ability to google quicksort and write it correctly, you should find another career.
@netssrmrz9 сағат бұрын
great video. would love to see a version for frontend.
@tomasprochazka619810 сағат бұрын
The initialization of Set takes some time though, should be included in the benchmark too
@zeikjt4 сағат бұрын
Only if the Set is temporary, if you use a Set instead of an Array altogether then it's the same thing.
@piff57paff4 сағат бұрын
Even then, there is more overhead during insertion. So you still need to look at it holistically.
@zeikjt4 сағат бұрын
@@piff57paff i suppose it does depend on whether the data is always created in bulk or incremental. This is why you don't find bottlenecks via these kind of benchmarks, you time your real code so you know the situation
15 сағат бұрын
Deno is becoming awesome
@vaisakh_km13 сағат бұрын
All thanks to bun.. Our cute little deno couldn't haddle the competition from Js's round buns XD
@RustIsWinning12 сағат бұрын
@@vaisakh_kmHahaha nice copium from the runtime with 500+ segfaults 😂
@thatsalot357712 сағат бұрын
@@RustIsWinningyeah but you can't deny the fact that they're the reason why deno is atleast trying to do better because pre deno 2 there wasn't much reason to use it. And I find bun to be still pretty good for servers and web sockets
@RustIsWinning9 сағат бұрын
@@thatsalot3577 Wrong. Yall just living under a rock and getting benchmarkbrainwashed by twitter influencer andys who are still stuck with the worse ecosystem lmao
@vaisakh_km3 сағат бұрын
@@RustIsWinning there is no wrong or right... compatition is always improves the products.. period. I don't and never says bun is better than deno... deno will be always better at compatibility due to v8 engine
@jackgame88416 сағат бұрын
i could become performance engineer after this course
@deatho0ne58712 сағат бұрын
forOf is my goto now a days for looping. One it is one of the faster and it is also easiest to think about in pseudocode.
@QuentinBzt54 минут бұрын
Bro is sold to the DENO cause, we wanna see Bun content as well 😛
@danser_theplayer016 сағат бұрын
I have one easy tip for performance. All array methods suck arse, and are hard to read, just write a for loop. This is the best answer every time all time. There is no question. If you do more than one thing then you'll chain methods without realising that you're looping more than once. Even if you don't chain, you still need to run a callback on methods. The for in/of loops are generators. Therefore the fastest is ALWAYS a regular for loop. I only write for loops because I don't know for sure that the array or object will be small enough, and also for loops are extremely versatile (doing what you usually do with 3 loop methods, in one loop), and readable.
@oleg496628 минут бұрын
Eh, I'm quite fond of filter and sort methods. They're a PITA to translate to a pure for loop, and the resulting code is hard to read.
@DomskiPlays14 сағат бұрын
Started a new job a few months ago and have fallen in love with maps and sets in combination with the data array. Fuck the users RAM, they want SPEED :D
@brandongregori9959 сағат бұрын
You should look into sparse sets. They are pretty cool. It's like a faster map
@WiseWeeabo7 сағат бұрын
let a = new Array(42); if (Object.seal) { a.fill(undefined); Object.seal(a); } Use fixed length arrays if you want to be fast.
@codernerd707615 сағат бұрын
Deno course!!!
@gro9676 сағат бұрын
"scientifically faster" is the important part of the video title.
@CottidaeSEA10 сағат бұрын
Premature optimization is no good, but don't write code with poor performance if you know it'll process a lot of data. It's not premature at that point.
@amine72 сағат бұрын
How else would you later make your service 5x faster and create a blog post and a youtube video bragging about it?
@CottidaeSEA2 сағат бұрын
@amine7 Could do what a colleague of mine did. Do a big import, loop through the file and compare for every potential matching item in the database. That way I could improve the performance by 1000x.
@nicsilver1212 сағат бұрын
Are you ok man? You sound a little down compared to your usual. Either way awesome video!
@aleksander529815 сағат бұрын
In the sumUsingForLoop you should make arr.length a separate variable to make it faster
@whyneet13 сағат бұрын
In databases, the index lookup performance is not O(1), but O(log n) assuming the index uses a B-Tree
@pixiedev12 сағат бұрын
Right, but he is not talking about database. it's for Set which uses hashing and is O(1) in almost every time.
@Exilum10 сағат бұрын
Sets are almost always O(1), and the worst case isn't even that bad.
@dave60129 сағат бұрын
@@pixiedevhe compared the O(1) lookup of a Set to a database index, which as @whyneet pointed out, is not O(1).
@MaulikParmar21012 сағат бұрын
Irony is people want performance from high level language like JS for which multiple runtime exists, each trying to impmement same stuff very differently from each other. If you really need it, than you won't be using JS or Go or even rust and rely C for close to metal performance. It also has own abstractions so it really drills down to a Software Engineers ability to understand machine at it's core level. Unfortunately alot of devs are not computer engineers or taught formally about computer architecture so squeezing out performance would be done by someone who excels in both relms and most of the world won't even need that kind of optimizations either. Thus compering benchmarks is pretty amature, at the end of the day solution and it's worthiness totally depends in usecase specific implementation. These type of comparison is inevitable because of lack of education on topics thst really matters after some point. And no if you're writing your app in JS for loading millions of records, that's not going to give you performance that a bare metal code will provide. Choose your tools wisely.
@funkmedaddy6 сағат бұрын
In a perfect world you get to choose your tools, but we do not live in a perfect world and sometimes you're just given the tools and have to work with them. While it's worth pointing out that JS should not be your language of choice for performance oriented tasks, it doesn't mean you can't try and make the best of what you have
@vighnesh15356 минут бұрын
In the bubble sort implementation, I noticed that you were swapping variables using the array destructuring syntax: [a, b] = [b, a]. For small arrays, this is fine, but if the arrays are large, then creating a new array allocation just for swapping might also cause GC which will slow down the entire bubble sort impl. For benchmarking, it would be better to swap the variables the tradition way by creating a temp variable.
@FirroLP11 сағат бұрын
If you can still change the video in your course: Not including the creation in the benchmark is a big flaw because creating a set is slower than an array. Obviously doesn't make such a difference, but it's a mistake and worth talking about
@zeikjt4 сағат бұрын
I think y'all are thinking that you'd still have an Array, but why? Just use the Set the whole time, no need for the original Array.
@jimbobu7 сағат бұрын
JavaScript developers when iterating over an array is slower than a single equality comparison: 🤯
@82TheKnocKY8 сағат бұрын
These examples don't consider the fact that JavaScript is a JITed language. These microbenchmarks are never accurate to how little/much this function would actually get optimized if it was in a real application
@sugaith8 сағат бұрын
these Rob Pike rules are perfect
@JimmyCerra12 сағат бұрын
The Centauri write in Javascript. The Narn write in Python. The Shadows use C++. The Vorlons use Java.
@npc-drewСағат бұрын
...and God write in Rust. 😎
@theprantadutta5 сағат бұрын
Performance, you say, I have never heard of it.
@edumorango14 сағат бұрын
One hash map to rule them all
@zeikjt4 сағат бұрын
Lua got it figured out!
@Roboprogs9 сағат бұрын
Thanks? I’ve been programming for 40 years, and these days I generally don’t worry about performance in the browser or Node, other than code and data size. The sort and search stuff pretty much all happens in the database. So I have to make all the execution time measurements against THAT, and avoid crippling it with stupid crap like ORM. So, yeah, same process, but not the place I run it. Batch C code on files in the 90s. Again, same process.
@krowhenkvothe601014 сағат бұрын
Like for the DENO course
@npc-drewСағат бұрын
like because this account is a bot.
@ciCCapROSTiСағат бұрын
Yeah, to be fair if you are speed conscious, you shouldn't use js. That doesn't mean you should ignore speed best practices of course. But doing big data in JS is just asking for trouble. That's what Python is for, with its C bindings.
@RustIsWinning12 сағат бұрын
Deno is so winning!! B word could never 😂
@kacaii334914 сағат бұрын
More videos about Deno please!!
@madbanana228 сағат бұрын
Best js benchmarking strategy: 1. Are you using js outside the web frontend? 2. Don't
@ktech42463 сағат бұрын
All this time i have be using traditional for loops because I was too lazy to learn a cleaner way. Looks like my laziness has paid off!
@muscifede14 сағат бұрын
code simple, test thoroughly, fix it
@danser_theplayer016 сағат бұрын
But if you're really looking to optimise a sorting algorithm, and have solid static typing, and don't want to learn a completely different language... Use a systems language like assemblyscript.
@jordymaryns494515 сағат бұрын
I hope there will be a lifetime purchase option in the future as well.
@DoubleDYouTube12 сағат бұрын
When you're creating a new set of 10 000 elements, you're using a lot more memory in comparison to using "includes". It's still a much better solution, but I feel like it should be mentioned at least.
@user-ii7xc1ry3x15 сағат бұрын
YAY new course!
@RealRogerFK10 сағат бұрын
Unless you're doing a game, game server or something that's REALLY mission critical these silly little benchmarks are more of a "Okay, this little replacement takes me 10 mins to implement and saves me this much ram and lets me have up to 10K users instead of 1K" In reality, you don't even have 10 users, but at least you'll sleep well knowing Bun takes less RAM... b-because i-it does, r-right?
@B1aQQ9 сағат бұрын
It's a misleading oversimplification to say the type of loop doesn't matter if the array is small. It might not matter if it runs infrequently. But if it's a part of a high traffic path, then you can have hundreds of small loop executions a second and that would mean the small differences can compound into an impactful performance hit.
@trappedcat361514 сағат бұрын
It matters if the array is large... or if the number runs on that small array is large
@Kiyuja8 сағат бұрын
trad loop gave me life
@pippinproductions14 сағат бұрын
java script users when they discover what a set is
@stereocodes14 сағат бұрын
what's java script? Java users when they learn its actually Javascript and has nothing to do with Java.
@unknownguywholovespizza12 сағат бұрын
@@stereocodesit's so annoying when people say Java instead of JavaScript
@fghdfghdfgghdstwesdfjtykjyfgk11 сағат бұрын
@@stereocodes but oracle owns javascript 🤔
@robinmitchell68032 сағат бұрын
5:16 -> Did you include the time to organise that array? If not, you can't compare the two.
@BritishBagelGaming9 сағат бұрын
5:35 , thought it would be fair to include the initialisation of Set from the array within the benchmark, no?
@itsmenewbie039 сағат бұрын
Rust mentioned let's Goooooo 🦀🦀
@MelroyvandenBerg8 сағат бұрын
Gooo also mentioned
@MelroyvandenBerg8 сағат бұрын
Gooo also mentioned 😅
@RustIsWinning4 сағат бұрын
Winning! Zig could never lmao 🦀🦀
@floppa941513 сағат бұрын
"Premature optimization is the root of all evil" is one of the dumbest quotes, especially if you think about things on a larger scale. If your architecture is stupid and leads to brutal overhead, for example by needlessly splitting up things into microservices that communicate over rest, you can't "optimize" yourself out of that easily. At that point you have to basically start over.
@morchellemusic282910 сағат бұрын
I think you got the quote wrong dude 😂
@musicstar88855 сағат бұрын
Best video till date
@MelroyvandenBerg8 сағат бұрын
Instant tinnitus due to your sound effects 😢
@JJJMMM14 сағат бұрын
5:40 the analogy between database indexes and O(1) Set lookups doesn't make sense to me. Most database indexes are stored as B-trees or B+trees, and the lookup complexity there is O(log n). So either the time complexity of a Set lookup is also O(log n), or the Set is actually stored as a hashmap - which is what I would've guessed - giving you an average case of ~ O(1).
@IngwiePhoenix13 сағат бұрын
So, how many "nodejs-bench" packages do exist by now?
@sugarsama771614 сағат бұрын
It's kinda misleading... I run a bench with the same quicksort implementation, and it was about 97% slower than Array.prototype.sort,
@ucmRich14 сағат бұрын
*** How can we put JavaScript (or the whole deno) in a cpp program for use as a scripting language for programming game logic in a 3D game engine? DXStudio used JavaScript as it's scripting language and I want to put that into another game engine or just make my own game engine with JS. Can Deno be used for this?
@darkenlightmage12 сағат бұрын
If you include and link the node or deno (or just the V8) runtime with the project, you can directly invoke the interpreter inside whatever application you want. It is then a matter of passing the right values to the interpreter environment so that you can modify external values using JS.
@AndreSpecht15 сағат бұрын
Amazing video. Could you share the code? Would love to use it with my students
@Filaxsan7 сағат бұрын
GOLD video!
@alekseykarpenko26812 сағат бұрын
Would these results be different in Node?
@cathalogrady233110 сағат бұрын
I feel like you have to apply pikes principles a bit different considering JS doesn't even have an optimizer.
@AvanaVana2 сағат бұрын
Why didn’t you include the array to set conversion in the benchmark for set?
@marcmcintosh67158 сағат бұрын
can you add to the suite? ``` function sum(arr: number[], count = 0) { if (arr.length === 0) return count; const [head, ...tail] = arr; return sum(tail, count + head) } ```
@mateja17613 сағат бұрын
I wish JavaScript had zero cost abstractions.
@floppa941512 сағат бұрын
At this point you don't have JS
@thatsalot357712 сағат бұрын
Dude it was supposed to be a frontend language, which runs in browser and was used to make buttons go click click, at this point you just like the js syntax.
@monawoka9712 сағат бұрын
Traditional for loop is fastest. C chads knew it all along.
@narrei66614 сағат бұрын
does set also work this well for array of objects?
@ence784610 сағат бұрын
no
@turun_ambartanen10 сағат бұрын
at 5:40-5:50 you say that a JS set is like a DB index. Is it really? I would have expected the set to work on hashes, but the index to work on a balanced binary tree.
@ence784610 сағат бұрын
This is an implementation detail but Set are just binary tree in js, like Map
@jontancool918113 сағат бұрын
This was uploaded at a perfect time as i was planning to work with benchmarking of a framework for my exam work
@Waterfly-v7q10 сағат бұрын
Nice guide how to look at JS (meaning the most popular runtime V8) perf like a amateur xd
@brogotbonkers13 сағат бұрын
that's an ad? I've tried to create a blog with Deno but it really sucked. not even close to what Ryan promised on demos lol
@RandomGeometryDashStuff13 сағат бұрын
06:22 does `[result[j], result[j+1]] = [result[j+1], result[j]];` create and iterate array?
@codyrap9511 сағат бұрын
It creates a temporary array in memory and then destructures it as it's easier than creating a third variable to store the temporary value of result[j]
@LuanDavi9 сағат бұрын
amazing content!
@anb43516 сағат бұрын
Damn foreach loop is bad. I have pretty large foreach loops throughout my codebase
@tomasprochazka619810 сағат бұрын
Why it isn't optimized by a compiler ... oooh
@fermin7c19 сағат бұрын
You keep calling functions passed to a method "callbacks" when they are just functions, nothing is calling back to them, they are just executed
@1apostoli6 сағат бұрын
strings sort by radix
@robchr13 сағат бұрын
What is the zeroith rule?
@anotherone239812 сағат бұрын
use C.
@samuelebernardi116212 сағат бұрын
Wouldn't the time to copy the array items to a set be longer than the actual research?
@mrdmajor10 сағат бұрын
It's hilarious watching web developers rant about performance but then also be hypebeasts for bloated frameworks, to build "apps". 🤣