r/programming • • Jul 05 '15

Fast as C: How to write really terrible Java

https://vimeo.com/131394615
1.1k Upvotes

394 comments sorted by

View all comments

Show parent comments

3

u/__Cyber_Dildonics__ Jul 06 '15

I don't know what to tell you. C++ for the main program, ISPC for tight loops over linear memory. AVX instructions can do 8 floating point operations with one instruction. It can take planning to line up data correctly but pixels are an easy case. By remap I mean taking values from one range and transforming them into a different range. That means a subtraction, division, and multiplication per value.

I was able to do over 6 billion per second on a 3ghz sandy bridge core. I marveled at how fast it was. Intel processors are incredibly fast, but most software utilizes a tiny sliver of their possible performance because people still plan programs like they are using a machine from the 80s. Getting to every last flop is about linear memory, cache coherency, SIMD, and parallelism.

1

u/heimeyer72 Jul 06 '15

C++ for the main program, ISPC for tight loops over linear memory.

Aha. :) Thanks.

That means a subtraction, division, and multiplication per value.

I was able to do over 6 billion per second on a 3ghz sandy bridge core.

I'm shocked. Anyway thank you very much!

1

u/F54280 Jul 06 '15 edited Jul 06 '15

Recent CPUs are absolute beasts.

Code from a StackOverflow question

$ cc -O3 main.c -o main
$ ./main 10000
addmul:	 0.140 s, 10.044 Gflops, res=7.030091

On a MacBook Pro laptop...

Your problem is not doing the muls, your problem is feeding the data. This is the only thing that matters on moden CPUs...

edit: the code is from the original question, not even the ultra-optimised answer