Live data from Hacker News

Beating C with 70 lines of Go

ajeetdsouza.github.io

61–70 of 106 posts

Re: Beating C with 70 lines of Go

#61
post #25

> Go can be a viable alternative to C as a systems programming language Stop this nonsense please. This does not show anything even remotely close to systems programming capability of Go. Write a device driver in Go that performs without lagging, benchmark it and then come back.

https://news.ycombinator.com/item?id=18399389 . It's been done. Performs well.

They quite literally were forced to use C for some parts because Go is not a systems programming language. They write this in the article.

Re: Beating C with 70 lines of Go

#62

How many times have the tests been run? Once? First for C, then for Go? What about disk caching then? What I can see there is that for the same algorithm, the Go version was not so fast. It was comparable. The memory overhead could be caused by the size of the program, as wc has more functionalities. Then there is compared a totally different algorithm with a false claim "this way a go implementation is faster than a…

The tests were run 10 times, and I used the median value. There wasn't much variance between runs, so I don't think disk caching played much of a role here.

Being a garbage collected language with a runtime, Go certainly cannot match the performance of C, and it was never my point to prove otherwise - obviously, for the same algorithm, the C implementation would be faster. Instead, I was exploring Go to highlight how simple it is to write safe, concurrent code in it.

Re: Beating C with 70 lines of Go

#63
This is excellent for showing how to do X in Y language. But like most benchmarks - it's a bit silly. If speed was the priority, you could parse only 1% of the file, then multiply the values by 100, assuming the rest of the file looks alike. Do you really care to know the file has 1337 words rather then ca 1300 words?

What about power consumption?

Re: Beating C with 70 lines of Go

#64

I'm really surprised by how much memory this task needs. Using a 16KB buffer and incrementing an integer needs multiple MB. I guess that's the size of the executable after it's been loaded into RAM that's so large?

The size of a compiled Hello World program is 2 MB on my machine, so you're probably right!

Re: Beating C with 70 lines of Go

#65
post #17

Earlier quoted context omitted.

I actually disagree. If you look at the code written in the article, it's hardly unreadable or very code golf-y as you suggest. I think the author is really just trying to say that programmers shouldn't dismiss Go as a possible systems language in favor of C just because C has a reputation of being faster in all cases.

Are we really saying a garbage collected language should be considered for a systems language? I know the GC is fast but surely memory managed languages are going to have less issues with pausing during execution, no?

Yes, as proven multiple times, and being pushed forward by the likes of Apple, Google and Microsoft.

Regarding using Go as a real systems language (in the same meaning as C):

- gVisor hypervisor on Google Cloud and Linux sandbox on Chromebooks

- Android GPGPU debugger

- Fuchsia TCP/IP stack and volume management

- Baremetal TinyGo on Arduino Nano33 IoT, Adafruit Circuit Playground Express, BBC micro:bit among many others

- Coreboot firmware

Re: Beating C with 70 lines of Go

#66

Alternatively, here's my entry for "Beating C with 40 lines of C": https://pastebin.com/JzFfE5GB $ time wc -w 100m 2266395 100m real 0m4.568s $ cc -o wc wc.c $ time ./wc 100m 2343390 100m real 0m0.511s Of course, it disagrees on the answer, because I just used 100M of random data and it doesn't care about wide characters. It gives the same answer as GNU on plain ASCII text. It's not faster because it's better, it's f…

> It's not faster because it's better, it's faster because it is doing less.

I can't recall who said it, but this reminds me of this idea: If you don't care about correctness then I can make it as fast as you like.

Re: Beating C with 70 lines of Go

#67

Yeah, let me just multithread and hand-optimize the piss out of this Go program until it's marginally faster than it would have been in C. Reminds me of the argument that venison tastes better than beef. The argument roughly being, "If you shoot the deer right, drag it home right, gut it right, skin it right, tenderize it right and cook it _just_ right, it'll be _almost_ as good as store-bought frozen beef"

Yeah, just like C developers used to do to try out beating Assembly programs coded by junior devs back in the 8 and 16 bit days.

Funny how times change.

Re: Beating C with 70 lines of Go

#68
post #25

> Go can be a viable alternative to C as a systems programming language Stop this nonsense please. This does not show anything even remotely close to systems programming capability of Go. Write a device driver in Go that performs without lagging, benchmark it and then come back.

Yep, real nonsense, that is why this stuff exists:

- gVisor hypervisor on Google Cloud and Linux sandbox on Chromebooks

- Android GPGPU debugger

- Fuchsia TCP/IP stack and volume management

- Baremetal TinyGo on Arduino Nano33 IoT, Adafruit Circuit Playground Express, BBC micro:bit among many others

- Coreboot firmware

- Biscuit POSIX like OS

Re: Beating C with 70 lines of Go

#69

> I hope it demonstrates that Go can be a viable alternative to C as a systems programming language. Are you kidding me? This is nothing close to a systems programming language. This isn't much of a comparison at all. wc is a very simple case that doesn't match the complexity of real-world programs. Go comes close here because you're not using the high-level abstractions and that make it useful in the real world. GNU…

These ones are:

- gVisor hypervisor on Google Cloud and Linux sandbox on Chromebooks

- Android GPGPU debugger

- Fuchsia TCP/IP stack and volume management

- Baremetal TinyGo on Arduino Nano33 IoT, Adafruit Circuit Playground Express, BBC micro:bit among many others

- Coreboot firmware

- Biscuit POSIX like OS

ISO C does not support AVX-512, and plenty of languages do as language extension.

Re: Beating C with 70 lines of Go

#70
post #44
post #34

Earlier quoted context omitted.

Furthermore this isn't "system programming", he just replaced a "user land" program with another. But I blame the Go team for turning "system programming" and "realtime programming" into useless buzzwords to promote their language.

Yeah when I first looked at go that was the first 'no fu' for me. Go isn't a systems or real time programming language. It's a managed language with training wheels. Which is okay by me. Lying about it though is not okay. The second FU is they claim that decisions they made based on personal preferences were technical ones. That's a very insidious lie that programmers make all the time. Insidious because it destroys…

This is not lying:

- gVisor hypervisor on Google Cloud and Linux sandbox on Chromebooks

- Android GPGPU debugger

- Fuchsia TCP/IP stack and volume management

- Baremetal TinyGo on Arduino Nano33 IoT, Adafruit Circuit Playground Express, BBC micro:bit among many others

- Coreboot firmware

- Biscuit POSIX like OS

But whatever, the GC-FUD is strong among C devotees.

Post reply on HN