And some retards still believe the compiler will optimize everything for you.
>>106960353ok but span is safer
How does span work under the hood?Is it like range in Python, where it creates a list that you then iterate over?
>>106960353Because you construct the span every loop. Retard
>>106960353Did you turn compiler optimizations on?
>>106960882Why can't our friend the clever compiler optimize it out?
>>106960882no?
>>106960353>meme "problems"the only thing more retarded than sepples are those
>>106960353Rust doesn't have this problem.running 3 teststest tests::bench_fast ... bench: 4,499.43 ns/iter (+/- 95.62)test tests::bench_idiomatic ... bench: 4,482.95 ns/iter (+/- 46.71)test tests::bench_slow ... bench: 4,501.73 ns/iter (+/- 10.81)
running 3 teststest tests::bench_fast ... bench: 4,499.43 ns/iter (+/- 95.62)test tests::bench_idiomatic ... bench: 4,482.95 ns/iter (+/- 46.71)test tests::bench_slow ... bench: 4,501.73 ns/iter (+/- 10.81)
>>106960911compiler devs and sepples committee talk big talk but can't walk the walk as usual>brooo our compiler is super smart giga AI powered advanced algorithms and can optimize everything>muh premature optimization is... LE ROOT OF ALL EVIL, o algo>Muh sepples zero cost abstractions n'shiiieet
>>106961306Stop speaking like a nigger.
>>106960353>spans suckalmost like most shitty C++ features and their implementations are malicious compliance.
>>106961312ay yo man, i ain't a real nigga like yo pops, i's just be talkin like one cuz dem racis-ass crackas on 4chan start hootin' and hollerin' when i do. don't mind me cuh, i's be white as snow, y'gnomesayin? iss all coo, mane.
>>106961303based and idiomatic pilled. how will sepples sissies cope with this SAFE AND BEAUTIFUL implementation?
>>106961306>o algowtf does this even mean?
>>106961360O almighty god of ALGOrithms, O Algo!>>106961303>short and simple code that gives the exact same result compiling to a different assemblyMuh llvm is sooooo advanced o algo
>>106961377>>short and simple code that gives the exact same result compiling to a different assemblyConsidering the speed is equal, this does not matter. Previous versions of Rust(eg 1.65) compiled it to the exact same machine code, but somewhere along the way they changed how this kind of code gets optimized and now iterators get inlined differently than ranges. There is still no measurable difference in performance.
>>106961401It does matter because the code in the first window creates longer and probably larger assembly code. If they could shrink down the assembly without affecting performance, why not do that?
>>106961360or something in beanspeak o algo
>>106961423>If they could shrink down the assembly without affecting performance, why not do that?Because compiler only knows limited set of optimizations it can do in reasonable time, and these optimizations have to be universal enough to work on wide range of different platforms and architectures. These snippets of code generate IR distinct enough to trigger different kinds of optimizations which result in slightly different machine code.If you want to learn more, you can use godbolt optimization pipeline analysis and look at it step by step too see what exactly happened, but I personally do not care enough to go through all of this.
yet another "forgot to turn on optimizations" threadbut yeah it's annoying that C++ is basically unusable with -O0
>>106960353I don't get it. What causes this? The possibility of arr/cnt changing mid-loop? But the loop did eat breakfast...
>>106961303
>>106961559>twitter e-celebBuy an ad and I might consider reading what you have to say.
>>106961559>gnu c/c++ versionsGNU coreutils are (almost) 100% C. Sepplesfags just won't shy away from cultural appropriation.
>>106961559do people who post this realize how low IQ they are?You can easily write something in some higher level langauge like javascript and shit all over some cnile diarhea purely because your algorithm actually uses a proper hashmap. All this shows is that gnu coreutils took over decades of effort to highly optimize specific cases that a relatively new project hasn't yet.
>>106960911Because it might have side effects, which would then modify the program behavior
>>106961572>>106961577
>>106961579Why can't our friend the clever compiler figure this out?
>>106961577>You can easily write something in some higher level langauge like javascript and shit all over some cnile diarhea purely because your algorithm actually uses a proper hashmapWhat makes you think the C versions use bad algorithms?
>>106960353You're doing it wrong.Span is used to eliminate the unsafe aspect of such crusty C-style code. Use it to wrap the arrays directly back at the caller, then pass and use that span in functions safely. Simple as.
>>106961604I didn't say that? are you those retards who fall for the>How would you feel if you didn't have breakfast?shit? low IQ nigger. learn how to read.
>>106961604What makes you reply to a Rust troon spouting nonsense, with even more nonsense? Only reason I can think of is that you're another Rust troon (or samefagging) and trying to create a pretext for more Rustroon rhetoric to be spouted.
lol
>>106961587Ok, so what are you even trying to say by posting some random article?If you are suggesting that the code I posted does not in fact sums the array, then you gotta argue it in better way than post an unrelated article about some unrelated project having unrelated problems.
>>106961616it isn't nonsenseafter the gzdoom drama, I found out abouthttps://github.com/Helion-Engine/Helionwhich shits all over all the cnile engines and it's written in C#.language implementation isn't that important for performance in most cases.
Reminder to ignore deranged Rust rhetoric and simply post Rust facts (>>106961629 >>106961587 >>106961559) instead.
>>106961616Meds. Now.
>>106961613What was the point of your post then?
>>106961629Yet another cnile forced to cope with fake graphs. It's like they don't even do basic fact checking and just fall for literal twitter troll in a desperate attempt to save their face lmao.https://x.com/kai_fall/status/1966158913478566093https://desuarchive.org/g/search/image/lpefOq3EscbItb7-JhCzyw/
>>106961587>>106961559lol. imagine trying to clone existing, documented, open source software and failing this hard. now imagine if they had to actually invent it from scratch
>>106961559>luncuck
>>106961821>imagine trying to clone existing, documented, open source software and failing this hardBecause project like wayland, pulseaudio, systemd, bash and even linux itself never had compatibility problems with their predecessors, right?
>>106961899>project like wayland, pulseaudio, systemd, bash and even linux itselfwhich reference implementations were they trying (and miserably failing) to clone?
>>106961552the span version compiles to comparison to end pointerint *end = arr + cnt;while (arr != end) { s += *arr; arr += 1;}seriously doubt this is 60% slower. OP probably just forgot to turn on optimizations so the span methods were not inlined
int *end = arr + cnt;while (arr != end) { s += *arr; arr += 1;}
>>106961925Wayland => xord, pulseaudio => OSS, systemd => init+many more, bash => Bourne Shell, linux => unixOver the years, all of them suffered numerous incompatibilities with the projects/systems they tried to replace
>>106960353kek so it is not just in js - other languages has this too.in js every loop perform slightly differently.for example negative loops are faster than positive ones.
>>106961971>xord*xorg
>>106961971the level of cope in this post is mindblowing. thanks for demonstrating why your community will never be taken seriously
>>106961997>thanks for demonstrating why your community will never be taken seriouslyOnly retarded normalfags do not take it seriously. Entire internet runs on Linux.
>>106962012ok, this is obviously a bot with a 200 token context window
>>106961982I wonder if the negative loop is so fast because it crashes on first iteration due to failed bound check
>>106961982Isn't reverse looping faster in all languages? Something to do with not having to check against the length or something? Also --i is better than i-- I think but that's probably optimized out.
>>106961982>200 iterations per secondwhoa
>>106962043Shouldn't the condition be evaluated before the first iteration?
>>106961958Test it yourself and you'll see.
Why does none of you ever look at godbolt.
>>106962091actually tried it and the end-pointer and span version is 60% faster, not slower
>>106962498that's -Og. on -O3 all are the same
>>106960447The tranny complex. Has to have safe sex because of dilation, now wants to force everyone else to do it too.
>>106960353speaking of compiling; on Gnu/Linux. I'm working on an experiment to try to compile a huge 30k line program on a cellphone. The program compiles just fine and works as expected on a desktop. It will probabbly compile on a cellphone running linux, and I'm curious about this as a stress test for the phone. Phone has 4 Gig of ram and 512 ssd. Any ideas or inputs would be appreciated.>Please wait a while before making a postwhy?
>>106962231GCC generates slightly different code.
>>106960353i have literally never heard about this or seen it used.
>>106960910>>106961532Man, people really just want to avoid this huh?
>>106964820Yeah I tried that code in godbolt it was essentially the same with O2 and O3.
>>106960353I have no idea what span is or does, sorry.
C++ = proven and tested tech for decadesRust = tranny shit
Do it properly (by not creating and destroying a fucking object in every iteration of the loop) and you will see that it's as fast as the C-style arrays in an optimized build.C-style arrays win in unoptimized builds though.https://quick-bench.com/q/QhGzLYaQJ9SL-BZpmdMSKWP1IZI
>>106961982As a developer, my time is more valuable than your CPU cycles.
>>106961629This is actually a graph of the average IQ of the programmers.
>>106961559buy an ad jewish niggerfaggot
>>106961303Now lets see the compilation times!
>>106960353never trust a retard to microbenchmark. that 60% might as well be pulled out of your ass.
>>106962498>>106962518retard wrecked again (this is not the first time OP has made a thread for this. he suffers from c++ derangement syndrome.)
>>1069620440 is the most often compared against number, so comparing against 0 is faster than ither numbers on most hardware
>>106962231where is the compiler output for slow()? why are you looking at the same output window twice? are you stupid or just dishonest?
>>106965418this is why you're being replaced by indians
>>106961423The part that does the addition is practically identical. The rest is barely different, not enough to show up in any workload
>>106961629This is the same guy who made this graph btw
>>106960353> function calls are slowerYeah no shit, function calls incur overhead. Are you actually retarded?
>>106970203>function calls incur overheadThat's not the problem here, and not all function calls incur overhead
>>106970379Shutup cnt.
>>106970572Nocoder kvetching
i don't get the obsession with rust in particular
>>106965279Wait, where is it destroying an object in the loop iteration?
>>106969371>where is the compiler output for slow()? why are you looking at the same output window twice?Because I attached compiled to the same source code twice by accident duh.>are you just dishonest?Yeah because I am a committee-paid shill trying to trick people into using std::span or some other shit lmao.
>>106971351to be also fair, you're using a nightly of clang as well
>>106971824Feel free to use any other compiler.
>>106961579>just solve the halting problem bro
>>106960353int cunt
>>106960353>Dumb nigger doesn't use compile optimization flag
>>106960353>spanThere's your problem. The only thing you should use from C++ is std::vector and even then it's easy enough to roll your own dynamic array. Everything else from C++ is pure bloat and unsneeded.
>>106972967>double indirection>another "this small slice of sepples I know is magically exactly all you need" retard
>>106973083Explain why anything found in C++ is better than just using plain C? Your inability to roll your own basic data structures is the only legitimate reason I've ever seen. If that's the case then get good.
>>106973161not anon, but most C programmers who are starting off just copy the best vector-like implementation off stack overflow or reddit, it is nice that C++ just has a vector, and std::string has small string optimization, and if you want longer strings, there is a LLVM library that has SmallStrings so you could have 200 byte strings before allocation, or you could just throw in a arena allocator (but it adds a pointer to each object, you could make a stateless allocator and make the arena/allocator global or thread-local, but when you have a ton of strings and multi-threadding, it's better to just stick to const char* and wrap it in the C++ equivalent if you need the size, for example you need the size if the string can't be null terminated, maybe you are parsing a file and you want to make a callback using the memory used for parsing).
>>106961640>motion sickness simulator>microshartno thanks
>>106973161Why use "plain C"? Anything I might want to write in C I can just write in C++.
>>106973576(nta)no you cantyou odnt have the restrict keyword. or vlasthe reason for the latter is fucking hilarious,fundamentally its because it """"breaks"""" the sizeof operator from what i heard
>>106960353Arr, what a cnt.
>>106973593>restrict keyword. or vlasnot anon, but it's __restrict in C++ and C++ has vla's, but msvc does not support VLA's for C23 or C++ or any future release.technically you could get VLA's working if you used the clang frontend for msvc (clang-cl or clang).I don't like vla's, I think it's deceptive because you assume arrays on the stack are fixed sized, but with VLA's you don't know, and now the code won't work on msvc (the main reason to use msvc is address sanitizer, on clang there are minor inconveniences such as the asan DLL path that's annoying enough to make you not use it, on mingw it's non-existant)
>>106973619regular cnts are still better than a lzcntand good god is there alot of em
>>106973711huh. i stand correctedand even if vlas are not portable, theyre still part of the language in my book.t. vile heretic
>>106973161Sure. First, can you explain why having the compiler automatically calculate sizes of data structures, member offsets for accesd etc. in C is better than just doing it yourself in B? Why is having different types like in C better then just everything beingbtypeless like in B?
>>106970379h0ly f*ck that is the cutest damn apu I've seen in my entire life
>>106973593Restrict is just a compiler hint brainlet. You are not writing different code
>>106973820>Restrict is just a compiler hint, brainlet.>You are not writing different codepick one and only one. especially if you start using various opti flags
>>106973748vla's are just a convenience, the criticisms that msvc has are legitimate.just use alloca if you want a stack overflow, just check if the pointer is NULL, instead of just crashing.In C++ you don't need to worry about it, all memory allocation failure just leads to a C++ exception, which leads to a debugger breakpoint if you don't catch it (basically the same result as abort / assert).while in C if you use mallco or alloca, you just don't get an error, you need to print it yourself (unless you use a VLA, which I really don't like the fact it will stackoverflow, the reason I don't like it is because it makes error handling not very convenient, for example, if you wanted to use a crash handler to save unsaved changes to a file, or send a crash report logs or files with something like bugsplat, a stack overflow is not a very safe state for your application to be in, unless your signal handler has a separate stack, but I don't know how that works in windows, but I remember stack overflows are not very recoverable).
>>106973932oh nevermind, alloca also stack overflows.I guess that gives more reason to use msvc-specific _malloca which needs _freea (it uses malloc after a macro defined size), I guess you could do this in linux as well by putting a header for the malloca block, but to keep it aligned you need to waste 8 bytes of header...
>>106973932>vla's are just a convenienceyes? no?i dont remember the last time i actually had to use oneon the other hand, C is the language of conveniences, when dealing with low level stuffthe usecase for c in tyotl 405 * 5 is when one has to write hacky shit to begin with, so in my opinion vlas fit perfectly well within the framework
>>106973984correct me if im wrongbut a fixed length array can also stack overflowa vla only means its allocated based on a runtime value
>>106974047yes, but generally it's impossible for your code to overflow if you don't use recursion, because the whole function call graph for your whole application could be mapped out to a maximum stack size.And on windows, the default stack is 1mb (I think), which is small (smaller than linux).