C++ is faster than C

C++ is faster than C

Postby Lyberta » 19 Mar 2020, 16:12

Deleted.
Last edited by Lyberta on 01 Oct 2021, 09:40, edited 1 time in total.
Lyberta
 
Posts: 765
Joined: 19 Jun 2013, 10:45

Re: C++ is faster than C

Postby smcameron » 20 Mar 2020, 07:08

But C is more fun than C++.

But on a more serious note, what i/o device are you talking about? I guess /dev/null is the fastest. But latencies and throughputs and syscall overhead of a real i/o device should swamp any language differences, I would expect (but maybe I'm wrong). To get the utmost performance out of high performance storage, you have to go multi-threaded... io_uring or the like. Beware of comparing a bad C++ implementation to a bad C implementation and declaring victory.

Edit: After a very quick glance at your github repo, I suspect you're not benchmarking actual i/o, but something else... data marshalling perhaps (but I might be wrong, it was a very quick glance.) For example it's not clear that you're taking the buffer cache out of the picture (via O_DIRECT).

Anyway, all that is fine, if you're getting better performance in real world applications, great. But it might not be better "i/o performance" the way storage people think of it, which tends to be along the lines of "how many 4k random reads can I do in a second?" "A million" would be a "very good performance" answer to that question say 5 years ago. I don't know what a "very good performance" answer would be today, but probably more than a million 4k random reads/sec. 5 years ago, this would require hammering on some fairly specialized storage with many CPUs concurrently. fio is the thing to test storage performance with.

Unless you're using something like NVME solid state or better, the software side of i/o performance literally does not matter. You could optimize it to the point that it was literally infinitely fast and took zero time, and it would make almost no difference because the disk is so comparatively slow. Who cares if you save a (metaphorical) second when the disk takes a (metaphorical) year to respond? Solid state storage does change this logic though, and that is a big, big change to an axiom that has previously held since the dawn of computers.
smcameron
 
Posts: 377
Joined: 29 Oct 2010, 23:44

Re: C++ is faster than C

Postby Lyberta » 20 Mar 2020, 16:25

Deleted.
Last edited by Lyberta on 01 Oct 2021, 09:40, edited 1 time in total.
Lyberta
 
Posts: 765
Joined: 19 Jun 2013, 10:45

Re: C++ is faster than C

Postby DrMcCoy » 04 Aug 2020, 02:33

You know what's even faster? mmap(): https://gist.github.com/DrMcCoy/10cac8f ... 5b0ad2e395

With the added benefit of not being 10x slower than fread() when compiled with -O0.

Sure, C++ is faster than C, if you're doing silly things like consecutive tiny reads that fread() was never meant to hyper-optimize.
User avatar
DrMcCoy
 
Posts: 14
Joined: 05 Feb 2015, 06:49
Location: Braunschweig, Germany

Who is online

Users browsing this forum: No registered users and 1 guest