[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


[Advertise on 4chan]


File: 1735933314704534.png (29 KB, 680x357)
29 KB
29 KB PNG
And some retards still believe the compiler will optimize everything for you.
>>
>>106960353
ok 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?
>>
>>106960353
Because you construct the span every loop. Retard
>>
>>106960353
Did you turn compiler optimizations on?
>>
>>106960882
Why can't our friend the clever compiler optimize it out?
>>
>>106960882
no?
>>
>>106960353
>meme "problems"
the only thing more retarded than sepples are those
>>
>>106960353
Rust doesn't have this problem.
running 3 tests
test 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)
>>
>>106960911
compiler 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
>>
>>106961306
Stop speaking like a nigger.
>>
>>106960353
>spans suck
almost like most shitty C++ features and their implementations are malicious compliance.
>>
>>106961312
ay 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.
>>
>>106961303
based and idiomatic pilled. how will sepples sissies cope with this SAFE AND BEAUTIFUL implementation?
>>
>>106961306
>o algo
wtf does this even mean?
>>
>>106961360
O almighty god of ALGOrithms, O Algo!
>>106961303
>short and simple code that gives the exact same result compiling to a different assembly
Muh llvm is sooooo advanced o algo
>>
>>106961377
>>short and simple code that gives the exact same result compiling to a different assembly
Considering 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.
>>
>>106961401
It 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?
>>
>>106961360
or 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" thread
but yeah it's annoying that C++ is basically unusable with -O0
>>
>>106960353
I don't get it. What causes this? The possibility of arr/cnt changing mid-loop? But the loop did eat breakfast...
>>
File: zero-cost.png (281 KB, 900x966)
281 KB
281 KB PNG
>>106961303
>>
>>106961559
>twitter e-celeb
Buy an ad and I might consider reading what you have to say.
>>
>>106961559
>gnu c/c++ versions
GNU coreutils are (almost) 100% C. Sepplesfags just won't shy away from cultural appropriation.
>>
>>106961559
do 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.
>>
>>106960911
Because it might have side effects, which would then modify the program behavior
>>
File: rust-breaking-linux.png (199 KB, 802x842)
199 KB
199 KB PNG
>>106961572
>>106961577
>>
>>106961579
Why 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 hashmap
What makes you think the C versions use bad algorithms?
>>
>>106960353
You'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.
>>
>>106961604
I 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.
>>
>>106961604
What 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.
>>
File: rust-security.jpg (181 KB, 1793x1179)
181 KB
181 KB JPG
lol
>>
File: 1665577052561946.png (28 KB, 120x190)
28 KB
28 KB PNG
>>106961587
Ok, 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.
>>
>>106961616
it isn't nonsense
after the gzdoom drama, I found out about
https://github.com/Helion-Engine/Helion
which 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.
>>
>>106961616
Meds. Now.
>>
>>106961613
What was the point of your post then?
>>
>>106961629
Yet 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/1966158913478566093
https://desuarchive.org/g/search/image/lpefOq3EscbItb7-JhCzyw/
>>
>>106961587
>>106961559
lol. 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 hard
Because 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 itself
which reference implementations were they trying (and miserably failing) to clone?
>>
>>106961552
the span version compiles to comparison to end pointer
int *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
>>
>>106961925
Wayland => xord, pulseaudio => OSS, systemd => init+many more, bash => Bourne Shell, linux => unix
Over the years, all of them suffered numerous incompatibilities with the projects/systems they tried to replace
>>
File: loops.png (87 KB, 998x701)
87 KB
87 KB PNG
>>106960353
kek
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
>>
>>106961971
the 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 seriously
Only retarded normalfags do not take it seriously. Entire internet runs on Linux.
>>
>>106962012
ok, this is obviously a bot with a 200 token context window
>>
>>106961982
I wonder if the negative loop is so fast because it crashes on first iteration due to failed bound check
>>
>>106961982
Isn'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 second
whoa
>>
>>106962043
Shouldn't the condition be evaluated before the first iteration?
>>
>>106961958
Test it yourself and you'll see.
>>
Why does none of you ever look at godbolt.
>>
>>106962091
actually tried it and the end-pointer and span version is 60% faster, not slower
>>
>>106962498
that's -Og. on -O3 all are the same
>>
>>106960447
The tranny complex. Has to have safe sex because of dilation, now wants to force everyone else to do it too.
>>
File: tippingCoffeefunny.png (578 KB, 759x844)
578 KB
578 KB PNG
>>106960353
speaking 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 post
why?
>>
>>106962231
GCC generates slightly different code.
>>
>>106960353
i have literally never heard about this or seen it used.
>>
>>106960910
>>106961532
Man, people really just want to avoid this huh?
>>
>>106964820
Yeah I tried that code in godbolt it was essentially the same with O2 and O3.
>>
>>106960353
I have no idea what span is or does, sorry.
>>
C++ = proven and tested tech for decades
Rust = tranny shit
>>
File: benchmark.png (36 KB, 1271x891)
36 KB
36 KB PNG
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
>>
>>106961982
As a developer, my time is more valuable than your CPU cycles.
>>
>>106961629
This is actually a graph of the average IQ of the programmers.
>>
>>106961559
buy an ad jewish niggerfaggot
>>
>>106961303
Now lets see the compilation times!
>>
>>106960353
never trust a retard to microbenchmark. that 60% might as well be pulled out of your ass.
>>
>>106962498
>>106962518
retard wrecked again (this is not the first time OP has made a thread for this. he suffers from c++ derangement syndrome.)
>>
>>106962044
0 is the most often compared against number, so comparing against 0 is faster than ither numbers on most hardware
>>
>>106962231
where is the compiler output for slow()? why are you looking at the same output window twice? are you stupid or just dishonest?
>>
>>106965418
this is why you're being replaced by indians
>>
>>106961423
The part that does the addition is practically identical. The rest is barely different, not enough to show up in any workload
>>
File: 1757769151212.png (81 KB, 1180x1051)
81 KB
81 KB PNG
>>106961629
This is the same guy who made this graph btw
>>
>>106960353
> function calls are slower
Yeah no shit, function calls incur overhead. Are you actually retarded?
>>
File: 1754963456161390.png (96 KB, 602x438)
96 KB
96 KB PNG
>>106970203
>function calls incur overhead
That's not the problem here, and not all function calls incur overhead
>>
>>106970379
Shutup cnt.
>>
>>106970572
Nocoder kvetching
>>
i don't get the obsession with rust in particular
>>
>>106965279
Wait, 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.
>>
>>106971351
to be also fair, you're using a nightly of clang as well
>>
>>106971824
Feel free to use any other compiler.
>>
>>106961579
>just solve the halting problem bro
>>
>>106960353
int cunt
>>
>>106960353
>Dumb nigger doesn't use compile optimization flag
>>
>>106960353
>span
There'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
>>
>>106973083
Explain 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.
>>
>>106973161
not 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
>microshart
no thanks
>>
>>106973161
Why use "plain C"? Anything I might want to write in C I can just write in C++.
>>
>>106973576
(nta)
no you cant
you odnt have the restrict keyword. or vlas
the reason for the latter is fucking hilarious,
fundamentally its because it """"breaks"""" the sizeof operator from what i heard
>>
>>106960353
Arr, what a cnt.
>>
>>106973593
>restrict keyword. or vlas
not 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)
>>
>>106973619
regular cnts are still better than a lzcnt
and good god is there alot of em
>>
>>106973711
huh. i stand corrected
and even if vlas are not portable, theyre still part of the language in my book.
t. vile heretic
>>
>>106973161
Sure. 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?
>>
>>106970379
h0ly f*ck that is the cutest damn apu I've seen in my entire life
>>
>>106973593
Restrict 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 code
pick one and only one. especially if you start using various opti flags
>>
>>106973748
vla'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).
>>
>>106973932
oh 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...
>>
File: free-internet.jpg (114 KB, 679x725)
114 KB
114 KB JPG
>>106973932
>vla's are just a convenience
yes? no?
i dont remember the last time i actually had to use one
on the other hand, C is the language of conveniences, when dealing with low level stuff
the 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
>>
File: kot-sushi.jpg (7 KB, 210x240)
7 KB
7 KB JPG
>>106973984
correct me if im wrong
but a fixed length array can also stack overflow
a vla only means its allocated based on a runtime value
>>
>>106974047
yes, 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).



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.