Does migrating code from to a C++ dll offer significant performance boosts?

I know simular questions have been asked before but I believe my specifics vary enough that this cam be it's own question. If I've missed another question that's very simular please link it for me.

I'm proficient in but a total novice at c++. I've got a subroutine in that just does a lot of maths. There's some trigonometry and squareroots etc. nothing too demanding but it's around 100 equations and they have to be run thousands of times.

Here's some pseudo code of what I do:

Sub mathsub()
For i = 0 to arraylength
A = somenum(i) * othernum(i)
End sub

So I do all the math inside the for loop many thousands of times. Each time uses a different element of a bunch of arrays (somenum, othernum, etc.), all of these arrays are the same length.

No single line of code takes any significant length of time (when profiled each line takes a negligible length of time), but all in all the program takes longer than I'd like. Can I expect a significant speed increase by rewriting this routeen in c++ and referencing it from

Edit #1 - answers to questions in comments

The code takes a negligible amount of time per array element but there's about 20,000 elements and I need to do this about 10,000 times (so 200 million times - no joke). All in I've estimated it taking around 18 hours based on how long it takes for a fraction of the work. The entire program will need to be run multiple times as well, although each new run is 100% separate an unrelated. I have tried threading the code, I have a Ryzen 1800x 8 core (16 thread) processor - I've tried splitting the task into exactly 15 thread (leaving 1 thread for overhead and other activities) and using a parallel.for loop and both don't offer enough of an increase yet. I don't know what AVX is, but I'll start looking into it, I've never written a line of C++, but the maths itself is all just simple equations and I'm happy to spend a few days/weeks/months learning implementing if it's seriously going to make a difference!

1 answer

  • answered 2018-11-08 07:24 hacksalot

    Benchmark it. There's no way to know that without benchmarking, but the answer is likely to be "yes" because of C++'s performance profile versus a managed language like VB.NET, but JIT optimizations, managed-to-native transitions, array access order / data locality, and general coding technique can all have an impact here.