Follow

I told someone today that C++ was now faster than C. He wasn't buying it. I challenged him to an optimization contest. I whipped up a C++ program to sort 2^31 randomly generated integers. It generates and sorts the integers in around 40 seconds on my machine.

I was evil, though I warned him that C++ now allows one to take advantage of modern hardware in ways that C does not. I used <thread>.

Technically, threading was added to the C standard in C11. But no compiler on Godbolt implements it.

@ratha Well, someone wrote one that took 15 seconds, but it used bin sort, and so took advantage of details of the data. Nobody has written a C program that uses a more general sort. My research suggests that 180 seconds is a lower bound on the time it would take.

@ratha - I ended up having to write my own. The C program took about 285 seconds to complete on my system. The C++ program that didn't use threads took about 210 seconds. And the C++ program that used threads took 40.

Sign in to participate in the conversation
hax0rz.lol

Where the 1337 meet to federate. Home of the most interesting local feed on the Fediverse!