Lua's Arrays are Wrong and YOU KNOW IT. (Coding in a Random Language Every Day)
HTML-код
- Опубликовано: 29 сен 2024
- Advent of Code 2023 is UPON US! What better way to spend the holiday season, learn to program, and test your skills against your friends. This year, I've decided to try something kind of insane. I'll be choosing a language off the wheel every day.... let's see what happens.
🏫 COURSES 🏫 Learn to code in C at lowlevel.academy
📰 NEWSLETTER 📰 Sign up for our newsletter at mailchi.mp/low...
🙌 SUPPORT THE CHANNEL 🙌 Become a Low Level Associate and support the channel at / lowlevellearning
🔥🔥🔥 SOCIALS 🔥🔥🔥
Low Level Merch!: lowlevel.store/
Follow me on Twitter: / lowleveltweets
Follow me on Twitch: / lowlevellearning
Join me on Discord!: / discord
Lua is the C of the interpreted languages, extremely simple and small. Probably the easiest language to teach kids programming.
I agree 100%, it's simplicity is masterful. It looks and feels nice too just like Ruby and Python.
love that
Comparing Lua to C is kind of unfair
@@torarinvik4920Python does not feel nice
@@FaZekiller-qe3ufbecause it feels awesome. Many built-in functions, structures, powerful slices, lambdas and iterators.
I'm doing all the challenges in C, which is my comfort language and the one I have to use the most at university (so it also allows me to practice a little bit with more difficult problems than I encounter in class). With multithreading and a fast language, part 2 is completely brute-forceable (took about 90s in my computer)
Doing my AoC in Rust to help familiarize myself with the language. Brute forcing with no optimizations took 71s for me. I wonder how much of that was due to my hardware vs how much was because of the program structure I was using.
I did the second part the optimal way, but by the time I've fixed all the bugs the brute force would've finished long ago
I solved it in Random Python:-). For part 2 I gave up on brute force and tried range mappings instead. It caused some headache to calculate all these range intersections - but it finally worked.
lua just seems like pseudo code with the indenting from 1 and the if ... then
you haven't seen COBOL, it's nothing BUT pseudo code and it's horrific 😱@thetukars
Urist picks up the +masterwork+ =diamond= ::continue:: label. The voidpointer is confused!
Man day 5 part 2 took me 8 hours to get it working in 1 minute++ in Rust Release Mode
If just Lua didn't start arrays at 1...
Somebody in chat gotta suggest he add LabView VI to the wheel
Cool video, lua is surprisingly integrated into many applications though. its good to know
Indeed!
neovim itself uses lua, btw
@@LowLevel-TVDon't tell @teej_dv the title of your video
it's cuz Lua is technically a C-library that can be embedded into (and augmented with) C code. Lots of game engines and user-configurable apps use Lua as a scripting lang for that reason
I will not stand for this slander of neovim's config language
Also world of warcraft addons
@@NostraDavid2 Also scripting language for roblox
Also Wezterm config language
and AwesomeWM's config language
Lua seems really popular for configuring stuff huh
@@murat.hroblox uses Luau
OpenMW scripting!
lua-jit is faster than python by a large margin and pretty light on resource consumption aswell.
normal lua is faster than python iirc
@@fhudufin to be fully honest, python is not a very hard benchmark to pull off lmfao
If it exists, it's faster than python.
well, the default Python implementation (CPython)
there are some which are A LOT faster
@@kuhluhOG mojo is closed source and extremely unstable, the python to c compiler is also very unstable. Apart from that I do not know of any other implementations that are faster than cpython especially now that it is JIT bit default.
roblox and fivem developers are shaking rn
The magic of Lua is that writing code in it just feels good. The syntax is so simple, there are super useful operators (# for length, .. for concat) and tables can represent a wide range of data structures and can even be used for OOP with meta tables.
Lua is pretty powerful, the issue comes down to how well you know it.
As someone who has a personal copy of the lua syntax manuel. Lua tables are amazing ❤❤❤
# is unintuitive for tables with discontinuous indices. It will give the length up to the first nil value.
The bruteforce approach is doable, especially if you multithreaded it. How do I know? Because I did that, like a complete cave man
ah, I didn't do part 2 because I saw the problem, found the smart solution to be too annoying to write for fun, and thought there's no way the bruteforce way finishes today
will do it then (although I chose to use js for today's problem which will slow it down even more)
Same. It's currently running
after about 40 minutes of running, I didn't manage to compute it, but I did manage to lock up firefox and to crash my mouse driver for some reason (this last part is why this is a reply and not an edit)
@@yjlom Did mine in Python. In a nutshell I created a worker for every seed range, and ran it using PyPy instead of standard Python interpreter. CPU usage hit hard 100%, went to grab a snack, came back and it was done. Looked at CPU usage history and it was interesting to see each CPU core usage gradually going down over time, as each worker was getting done
@@yjlom That's... that's kinda impressive ngl :DDD
Hot take... Lua should of been used for the web instead of JS
Funny you should mention it, since Emilua (basically lua's node.js) dropped a new version literally yesterday.
Based take.
true!
JS probably would have been fine if the creator was given more than 10 days to make it, and not forced to "make it look like Java".
@thetukars Brendan Eich (JS creator) said that if he was not forced by business, JS would be functional with Scheme syntax.
Your first videos about advent of code were very good. Now you cut to much. I can’t even read the instructions because you cut to much.
I am an embeded programer. I used lua since 2005. For me lua has three advantages.
1. Low memory foot print. Around 100k.
2. Lua is a language that is embedded language. This allows it to be easily embedded into an environment, unlike python which is very hard to do.
3. Lua is easy to interface with c code and c code interfacd with lua.
Amoung the things that I have done.
1 setup command shells inside low resource processors to for test and debug subsystems while the system is running.
2. Field lua on processors like esp32. Several lua tasks could be created using FreeRtos, which canot be done with micropython. Also, Lua can very easily integrate with Arduino c routines.
Lua loses its advantage when system get above 500 m where python and associated library come in to play.
As a closing not there is a lua engine written in go which shopify used at one time.
What are the 100k and 500m that you speak of?
@@MavikBow bytes of memory i assume
I hate the fact that RUclips is bugged on my end so that I can't see the "See More".
@@kuhluhOG try different account? if on PC try in guest mode maybe, probably an extension or your account
@@cocbuilds tried it already, doesn't matter
Next year please choose random languages that viewers suggests, including non-mainstream languages that may have to be learned from scratch
Do you want him to die?
@@CrazyLuke11 yes
🤣great user name btw
Add some esoteric languages perhaps? 👀
For added content make sure to include assembly. LLVM-IR is close enough and would be more fun to watch. You could call external functions to make it easier. Besides he already knows assembly so it would be too easy.
Lua is slow, but LuaJIT is the blackest magic there is
Lua is amazing its as simple as C and can get as complex as C++
if you start with Metatables and fenv (function evoirements) you can do amazing stuff for example in lua tables there is no such thing as private members
but with metatables and fenv you can get total support for private members
but also in reverse its usefull you can do what feals like reverse reflection
The complexity doesn't really depend that much on a language more like on the project itself.
@OneMilian it DOES depend on the language. For example take the C programming book,written by the creators of C and compare it with the book written by the creator of C++. You will see that there is a MASSIVE difference in their volumes. C is an extremely simple language which puts all the hard tasks on the programmers shoulders. Python on the other hand is an extremely complicated language because it can do almost everything with little to no external libraries. C++ is the hardest language there is IMO since it was designed to let the programmer program everything from super complicated operating systems all the way up to simple shell programs that are meant to execute a few simple shell commands
@@OneMilian i get what you mean and i agree most complexity comes from the project but i meant what @armincal9834 describes that the language has some parts that are just more complex in nature and if you use thes parts the project would also become more complex by default
C is not simple
thanks for making me aware about function environments
lua is an awesome language. Considering you have alot of C experience, you could modify the interpreter to your liking.
Excel (without macros) should be on the wheel.
I absolutely love lua
Lua is as fast as JS. LuaJIT is insane, similar to modern JS Jits.
It's not even close anymore sadly. JS is a minimum of 10x faster than luaJIT now
@@Pillboxing source?
where are the last few days?
He tweeted this:
no advent of code for a few days, traveling for work. its not because haskell is still on the board this isnt a cry for help.
@@joachimhorshauge oh lmfao
what kicked me in the balls about lua a few times is the fact that anything that could be a variable is basically initialized to nil. you can use a variable that was never declared and/or initialized. so if you do something like
if (varialbe == value) then
...
end
... but you have a typo in variable and write varialbe like the dyslexic idiot that i am, that condition will simply never fire. good debugging times ahead!
but otherwise it's a great language for simple interoperability and parametrization of large C and C++ programs :)
You CAN start tables (i think you refer to them as areays) from any number(even negatives that dont wrap around to the end i dont think) but all the standard linraries only use whats in indexes 1 and up. You can also use strings
that title single-handedly reduced Primegean's lifespan by 5 years
I was able to figure out an alternative to the brute force approach for part 2!
I modified my solution so that it processes ranges of seeds as start and end values, then splits those ranges into processed and unprocessable ranges. It then feeds the unprocessable range into the next line, and finally returns all of the processed and remaining unprocessed ranges together as destination ranges. It repeats this process for each mapping and then finally sorts the resultant list of ranges by their starting range and returns Start value of the first item in the sorted list of ranges :)
Very cool! I had the exact same idea and stumbled on the implementation. I finally got it to stop throwing negative numbers after a refactor, but ultimately failed to get a solution. I was up very late trying to debug it. Boy I wanted that star bad, but I had to give it up for bed. I will scratch it out eventually. Way to go!
@GordanCable Thank you! And I know the feeling! Good luck!!
Part 2 was such a pain. I just ended up using a brute force solution which took 8 minutes to run in python.
what?
me here stuck on day 3 and it seems i just peaked to day 5 and day 5 is just on another level of dificulty jump
@@kizigamer6895 That tends to be how Advent of Code goes. I don't think I've ever actually made it past day 5, as I start taking longer and longer to get working solutions. Luckily the puzzles stay up year-round so you can work on them slowly if you want.
My code for part 2 (in c++, brute force - check each seed number, and find the minimum result) took about 20 minutes ;)
@@wolodiam9013how did you make it slower than python? I'm genuinely curious.
What I did for part two was changing the representation of the seeds to be a tuple (min, max), so that you don't have to save every number in the range. Then you just check what part of that range is in the range given. You have to then create the ranges that weren't contained and also check those, but even in python the part 2 input takes a second.
Hahahaha... Rookie here. I just solved this question with JS. Part2 almost fried my cpu with 1 billion+ seeds until I reimplement it reversely 🤣
I was so excited to watch you do part 2 in Lua 😭😭
Would have suuuuuuucked with 1 indexed arrays lol
@@LowLevel-TV if it's really that bad for you, you can make arrays 0 indexed just by doing
{ [0] = , , etc }
Can you please make a video on macro/preprocessor in C? I like to look into the .h files in my /usr/include (habit taught to me by my prof), and there is some crazy wizardry with macros I just don't understand. It seems like a whole other language with its own syntax. I've even see stuff on SO about using macros for function overloading. So, even just a basic video on the foundation of the preprocessor and how to use it (effectively) would be sweet :)
Add Smalltalk to the board! Both Pharo and Squeak are good.
I only use lua for my neovim config 😂
I still want to see you try lisp
Once you realize that a Lua array is not an array, but is in fact a hashmap, the choice of indexing based on 1 no longer seems so strange.
I'm happy that I encountered 1-indexed languages before I got too used to 0-indexing, so now it's not only not a problem, but I even prefer it that way. I'm somewhat convinced a noticeable percentage of off-by-one errors are caused by 0-indexing.
Also, it's basically a C implementation detail, the way some people treat it as the One True Way to index arrays in programming is kinda dumb ngl.
A lot of the time, 1-indexing doesn't matter. It's mostly personal preference. However, it can be pretty annoying if you're doing a lot of math involving arrays. I was making a 3D grid data structure in Lua and I had to add some -1s to get it to work, which isn't great if you need high performance.
@@mxruben81 that's interesting. No way to change the way that structure works to be 1-indexing native? I'm genuinely curious about the details.
I'll have to correct you here, because there are actually legit good reasons why people don't like 1-indexing. First, 0-indexing is not a c implementation detail. People keep spreading that around and it's wrong. 0-indexing has to do with pointer arithmetic, which isn't exclusive to C. In any compiled language, under the hood, a fixed array is (mostly) just a pointer to a memory address. A pointer is basically an integer, and you add a value to it in order to access the next array slots. By default it naturally points to the first slot in the array, and if you add 0 to it, it keeps pointing to that slot. If you add 1, it points to the 2nd slot, and so on.
The array operator [ ] is syntactic sugar for the pointer arithmetic which would otherwise take a few lines of code to get done.
0-indexing is entirely preferable, because the indexing math only ever works with 0-indexing. In discussions about this topic, a lot of people confuse counting with indexing, but they're not the same thing and shouldn't be confused. With 0-indexing you can convert x, y coordinates into an array index using "x+y*grid_width", and from an index to x,y coords with "x = index % width" and "y = floor(index / width)". If you try to 1-index that grid, this won't work, and there's no way to adjust the math to make it work.
Moreover, when a language is "1-indexed", that means the language itself expects you to 1-index your arrays. This is why in Lua, for loops include the upper limit: they expect you to loop from 1 to the limit inclusive (for i=1, 10 do ...), and whenever you want to loop from 0, then you must never forget to subtract 1 from the limit, which is a bit annoying and error prone. And you can't use ipairs on 0-indexed arrays, or the # operator.
And then your programs will be inconsistent. You'll have arrays that are 1-indexed, others that are 0-indexed, and you either avoid ipairs entirely or you have to be paying attention where you can and can't use it, and sometimes you have to also pay close attention to code that interacts with both at the same time and requires indexing corrections.
It's also a PITA to create utility functions that work with arrays, because you can't predict what users will throw at them, so you have to waste more time and effort making the functions support both index bases and making sure they both work properly. Or even other utilities. I've written an Enum library a few years ago, and to this day I still haven't decided if it should assume 0 or 1 indexing by default...
It's also a PITA to port algorithms to and from other languages, as you have to keep attentively converting things to 1-indexing and making sure the algorithm doesn't break, or keeping 0-indexing and making sure you apply corrections to loops, or deciding which one to use... And then if the algorithm isn't working you have to double check the code, as well as all your array indexing conversions.
I've been coding in lua for about 5 years and I absolutely love it like no other. But 1-indexing has been like a rock in the shoe: you can learn to live with it, but it never, ever stops being annoying af.
@@skaruts Not to mention the fact that unless you are using luajit, if you 0-index, that data is in the hash part of the table instead of the array part, which hurts the performance of your code a bit. Not sure how much. I do agree, I would much rather just have 0-indexed arrays, but I've learned to adapt.
@@mxruben81 that's true, according to the 5.1 manual, at least. But tbh I've never noticed any performance hit from it, so I always just use what makes more practical sense.
I made a game of life in TIC-80, which doesn't use luaJIT and I tried both ways, and didn't see any difference. I was hunting for any micro-optimizations I could find.
lua is faster than python
This challenge is really the off-by-one challenge.
as all array access is with anything that's not APL
Its impossible to make off-by-one errors in APL
@@monad_tcp There are two types of programmers -- those that start counting from 0 and those from 1. And they never line up on anything.
@@monad_tcp Sure, and there's nothing preventing one from restricting oneself to using a matrix class that hides the zero vs one-based addressing. But unless that abstraction is near zero-cost, people using big data get pretty finicky when it comes to performance and may want/need to perform array dentistry themselves.
@@ericbwertz maybe that's why basic had `set base 0/1` or something. I though about Lua metatables, there's a way to do arbitrary indexing, but that would be definitively no a zero-cost abstraction.
In the end you're right, when you need performance, you have to accept less optimal code.
I did day 5 in C and the second part took my laptop more than 6 minutes to spit out a number and thank god it happened to be correct.
YOU WILL NOT BE FORGIVEN FOR YOUR HEINOUS ACTIONS.
How dare you calling LuaJIT slow?
The idx starting at 1 wasn't the worst, I just changed my thinking that it's all Tables and your can use index 0 it's just screws with the built-in metamethods like length, but you can write your own length method, which you need to anyway of you are using non-integer keys. What caught me up was that when Lua says local it means LOCAL. Had I bug that i just didn't understand and it's because I accidentally declared a local inside of an IF statement instead of before. Other than that, charming, small, easy to abstract language and I do love the logic passing values, and only nil and false being falsy has it's own advantages
I'm doing the whole AoC in Lua, did not expect to pop up here
Lua should release two versions of their interpreter, one that starts index at 0 and the other at 1. That way everyone is happy and all problems are solved.
Neovim users are in shambles
Please add FreeBASIC to the wheel please!
title is wrong btw, its day 5 :)
thank you!
lua is the fastest interpreted language though. its basically a wrapper around c. plus if you're doing game mods; gmod and WoW have lua scripting engines. and if you're doing cybersecurity; nmap and wireshark have lua scripting engines. goated lang
I am kinda disapointed about skipping part 2. I was waiting exactly for it :/ Bruteforce is a correct, but dummy solution :C
I know I really wanted to finish it, but unfortunately I had to go to my J O B XD
luajit can generate code that is as fast as c
love the series - you should put ocaml/f# on the board.
rust FP skills should transition really well.
i always wonder if one might use them as a scripting buddy language to rust (same language family after all)
lua is WAY faster then most interpreted progrmaming languages
3:50 "We're going to do '0+1' and you're going to be okay!" lol
bro had to change the title because of the backfire, love to see it
For part two, I brute forced all seed calculations in Go. Script took 3.5minutes 😅
Got it down to 15 seconds using optimizations and Go routines. 🥳
my code using divide and conquer on part 2 takes 17ms on Rust (1ms on --release), I'm quite proud of how it turned out.
I summed the amount of seeds it would need to process if you were to do brute force and it is over 1 billion.
Lua was my first crush before I hitched on to C
I coded my solution in C, and the bright side of this is that it's fast by nature, so I bruteforced it, and it took less than half a minute to complete
I found the better way to brute force part 2 is to work backwards through the mappings. You count up from 0 as locations, and work each backwards through the mappings to the seed-level to see if it was a valid seed. This is nicer because you can stop as soon as you find a result (the first location to work), since it by definition has to be the smallest, instead of having to process every input seed when going forward to prove that none are better than the latest minimum you found.
My go solution was under 5s that way, without any form of threading, compared to > 5 minutes going forward.
Note: I still tried the likely "intented" solution of processing each set of seeds as an interval, and have those pass through the mappings going forward. It took a lot of time to make sure my hand rolled ranges, and the interval splitting was working as expected so overall despite being 10x faster to solve (
Thank you. I've been reading tips for a long time now and this was the first time I understood the backwards approach. I'm gonna see if I can make this work!
ohhhh I saw someone say that they “did it in reverse” but this makes it a lot clearer how. I brute forced it in rust with basic non-parrelized iterators in rust (did some optimizations to my maps, parser types and iterator folding) and that ran on my PC around 1 mapping each 5-15 seconds for a total of like 1 minute and a bit. I wonder how much faster a “brute forced” version with this approach (same types) would be, parallelized
Finally someone with a sane solution! I got done with part one but had to go to bed before I could implement that algorithm, though I did sketch it out on paper first to avoid getting lost.
Fun fact: "Lua" actually means Winter Hat in my language and you're wearing one :)
What is your language ?
And it means moon in Portuguese :) Maybe now its logo will make more sense. It was created in Brazil too.
@@alstin112 Norwegian
Goto in lua works differently than goto in some other languages. Goto gets a bad reputation to my knowledge because some languages it can push you to unexpected places. In lua it has to be in the same scope. You can't goto a different function.
I do wish it had += and continue though
LuaU has both :)
@@arandomguythatdoesntpost I've been meaning to try luau. I shall do it soon
Part 2 sucked and it filled my entire day.
Use ranges (store only start and end) and do some set theory calculations (i.e.: intersections)
That's it
i’m doing that but dealing with off by one errors 😭rip
dont call lua slow its actually pretty fast and at 8 years after c++ its not exactly ancient either
I've never coded in Lua before, but as a mathematician, most other languages I've used are 1-based (R, Julia, Matlab, Octave, Maple, Maxima, and Mathematica). I haven't used Fortran, but I believe that's 1-based too.
I find 1-based a lot more intuitive, and most of these languages come with ways of handing arrays such that the odd occasions when 0-based makes life easier never really appear.
Me when I see people tell me Lua is a Brazilian language as a selling point (I'm Brazillian): "Yeah, Lua is Brazilian, AND THEY MESSED UP THE BASIC FUNDAMENTAL OF ARRAYS STARTING AT 0!"
Lua arrays arnt arrays... they are tables... also base 1 is infact liked alot... in CS like areas... base 1 indexing is infact better then base 0 as the results line up along with traditional counting... but any time you try and criticize, lua you will get alot of correction as you arnt allowed to say anything bad about it... 1 based indexing really isnt a problem.... that and lua is like the leading interprered language in gamedev and Lua is infact a vary nice language .... Lua's syntax is more clean then python (dont care... indenting only for nesting and nonsense isnt how code should be written)
Programming in Lua is reliving my childhood all over again programming in basic. Easy and pretty cool for making 2d games that does not require optimazation and enourmous computations. Löve this shit.
Roblox Developer here, lua/luau tables are probably the best thing i ever seen in my life, it can be anything, arrays, dicts, "objects", ...awesome.
lua is language for fliping tables🤣
I did it in Rust, and I parsed out each map in a Map struct, which is basically just a sorted vector, where each element is a tuple of a range to a range (i.e Vec ). This vector is basically just a poor man's table mapping src range to destination range. The vector is sorted based on the start of the first range i.e start of the src range. This gives us sorted intervals, within which you can just binary_search your seed. When you have parsed all the maps into a Vec, now you can just .fold over this vector and get out the final location. (maps.iter().fold(seed_i, |curr_seed, map| map.get(curr_seed)) ). Do this for all seed_i and get their minimum.
For the second part, I simply ran the new parsed out ranges of seeds (there were 10 ranges ig?) into their own threads. This was kinda hacky since some ranges were really large and some small, so not all threads got the same load. In fact, most of the threads finished within 4-5 seconds, except the last two which ran for a good 10 seconds more. Ultimately, the program terminated in 20-21 seconds, and I had the solution in my hands.
I feel this solution would be unfair to poor people with old computers. I have a mid-range laptop with 6 cores, so it wasn't that bad. So I think there might be some other solution that I'm not seeing.
Lua is just a new version of Fortran
Why doesn't someone just make a 0 indexed Lua? It's tiny and MIT licensed...
I like Luau (it's derived from lua) because it fixes a lot of the ugly parts of lua while staying simple giving you optional type annotations. It still has the 1 indexed arrays, but once you get used to it, it really isn't as huge of a deal as many make it out to be.
on the other hand Fortran is ancient and fast!
I started advent of code aswell, but it gets pretty tough when you do it all in C
Who else want to see real C
luaJIT also has ffi. which allows for manual memory managment. and is extremly fast
I ended up brute forcing it in Rust which took about a min or so. Spent like 3hrs trying to think of some complex set theory crap to map one range to another. Don't recommend lol
I just love living and learning. That people you were looking at as some sort of authority, do absolutely ridiculous nonsensical takes. And title was enough to se that. Makes you start think about all the shit you read on net.
Lua is great, and I'm not sure how slow could it be when it's used _extensiviely_ by video games, possibly one of most demanding fields of programming, one great example is spring rts game engine, game that regularly has thousands of units simulated real time, is using lua for defining and processing lots of those units, in real time game.
When I was playing WoW back in the day and learning Lua coding add-ons, my creaky old computer was running ridiculous amounts of Lua every frame.
Is Lua just Ruby? Or Ruby just Lua? They look quite same same on the surface.
You think that Lua's arrays are bad because you mistakenly think that Lua has arrays. It does not.
Let’s add Scheme to the wheel!
:(
Why does everyone call lua slow? Lua isn’t a slow language
I don't understand why hr used go to statements, there is break for loops...
Lua is awesome
this stream was really funny
You have no right to complain about old languages since you still use C 😂
Can someone just maintain a fork of lua that indexes arrays at 0. Thanks
me on my 5th nested for loop "this language is tomed bruh"
and now imagine that all mods for tboi and addons for gmod are written in lua
im learning lua right now fingers crossed this video helps
lua is that language that im just confused as to why it exists.
Part tow took me 43 min to compute in Rust unoptimized beginner level
edit: with release mode it ran in 2min 12 sec
Stupid me waiting for 40 minutes
Did you use release mode?
@@xObscureDarkness nope I'm a rust noob or I just started learning rust starting with this advent of code so I am probably doing very inefficient stuff
@@xObscureDarkness ok I ran it again and with release optimisations it took only 2min 12 seconds 😱
I wish I had known earlier
(I'm running it in wsl) idk how much of a difference that makes
I used parallel rust (rayon) implementation on 32 core machine and get result in 7.67 sec.
@@chillidog8726 In nutshell, rayon helps you to make your loop parallel. If you apply one function to all numbers in Vec one by one without any state, that is the best way to do it.
Tokio on the other hand uses async, which allows you to do IO (like waiting for packet) and doing something else at the same time, like computing something. It helps you to run your code concurrently on one core. But it also supports multiple core compare to python asyncio and GIL. So, IO operation will not block you core and during that time it can do something else.
enum DX {
Good(bool)
}
struct Language {
dx: DX
}
fn main() {
let lua = Language{
dx: DX::Good(false)
};
match lua.dx {
DX::Good(false) => assert!(true),
};
println!("saying lua is less cursed than cpp is straight blasphemy");
}
So I first learned LUA back in the day writing scripts for WireMOD for GMod, and then totally forgot about it until a few months ago, when I took over maintenance of a popular Cyberpunk 2077 mod which is written in LUA (it runs on the LUA sandbox someone else made that sits over the game)
At first I really hated it, but honestly now I find it refreshingly small, and frankly doing everything with tables is an interesting enough constraint that it lends itself to creative programming (though lot of this is made easier by the fact that the only "quality" I need to worry about is "does my code at least not explode other people's computers?")