Who will win 🥇- C++ vs Go language #cpp #cppprogramming #go #golang

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

to flush in a stdout at every iteration of the loop and it's a benchmark, you have to be a genius

hey-rglk
Автор

1.
2. Replace std::endl with '\n'.

Now try again if you dare! :)

mahdiramezani
Автор

std::endl will cause flush every time, which will make things slow. Replace std::endl with newline character and run. Without chrono time code and just loop, it took 0.3 seconds on my machine. Also, hope you are compiling with -O3 flag.

kinershah
Автор

"Yeah, I'm a programming influencer. How'd you know?"
*flushes stdout every iteration*

djiekamjskskwks
Автор

I mean I don't need to point out the fact that this is a "printing speed" comparison at this point, but if it is indeed the case then might as well do it properly for C++

1- replace endl with '\n', the std::endl function doesn't only do a new line, it flushes as well making it slower.

2- try these few lines of code at the start of the main function
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
The cin one is probably unnecessary, but this little function is what we informally like to call the "fast input/output" function more often used in competitive programming
Or if you don't wanna go for that then might as well go with a more c-style printf() function

joonyou
Автор

benchmarking by iteration, it is stupid

TaqiA
Автор

bro forgot the optimization flags for c++ 💀💀💀

dontreadmyprofilepicture
Автор

This benchmark did not tests anything related to the speed of go and C++. The only thing it tested was the intelligence of the OP. He failed the test.

ficolas
Автор

Look, I'm a fan of Go... But of course poorly written C++ will lose to Go.

That C++ code is so unoptimized it's wild. Also, printing to console is not a good benchmark imo.

AtariWow
Автор

The output is not properly visible because of the description

Manish___Choudhary
Автор

Go is a higher level simpler syntax language with same performance than a lower level language, thats what really sells it off

dtar
Автор

What kind of test should this be? Out of curiosity I just did your benchmark. Even with the unnecessary flushing through std::endl with a loop of 0 to 1, 000, 000. Both on the same machine (Intel i5-2520M), same terminal, compiled and run with Arch Linux:
C++ with std::endl (gcc, -O3): 2, 431 s
C++ with std::endl (gcc, -O0): 2, 869 s
C++ without std::endl(gcc, -O3): 2, 365 s
C++ without std::endl(gcc, -O0): 2, 433 s

Go (with official comp.): 3.422 s
Go (via go run): 3.527 s

So even without optimization C++ is faster.

Edit: Had to correct the execution times as I did an upsi by letting the cpp version run with only 100, 000. Numbers should now be correct.

TinyTeaKettle
Автор

If you are benchmarking any lang vs c/c++ you already showed your power level... and it's really !great

malusmundus-
Автор

Use "\n" in cpp, and compile instead of run on go

WilsonTech-go
Автор

that's printing speed, not looping speed - java will loop to 1 bln in 3 ms

sergeibatiuk
Автор

Use printf when doing lots of prints because you flush the system with each std cout

Jetforce
Автор

in c++ use \n in place of endl ...then compare speed...go wont even come close

hehehe
Автор

What are you benchmarking discard the output printing in golang you can use io. Discard and then check for memory allocations per operation and stuff like this to determine the performance gap

_us.m.an_
Автор

You serious rn? You are benchmarking a language by iteration?🙂

CheezePie
Автор

std::endl calls stdout's flush, which takes much much much longer than the entire loop combined in c++z. No joke

the-programing