简体   繁体   English

将代码从vb.net迁移到C ++ dll是否可以显着提高性能?

[英]Does migrating code from vb.net 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 vb.net but a total novice at c++. 我精通vb.net,但对c ++还是一个新手。 I've got a subroutine in vb.net that just does a lot of maths. 我在vb.net中有一个子程序,可以执行很多数学运算。 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. 有一些三角函数和平方根等。要求不高, 大约有100个方程,它们必须运行数千次。

Here's some pseudo code of what I do: 这是我所做的一些伪代码:

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

So I do all the math inside the for loop many thousands of times. 因此,我在for循环中进行了数千次数学运算。 Each time uses a different element of a bunch of arrays (somenum, othernum, etc.), all of these arrays are the same length. 每次使用一堆数组的不同元素(somenum,othernum等)时,所有这些数组的长度都相同。

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 vb.net? 通过用c ++重写该routeen并从vb.net引用它,我可以期望速度显着提高吗?

Edit #1 - answers to questions in comments 编辑#1-评论中问题的答案

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). 该代码每个数组元素花费的时间可以忽略不计, 但是大约有20,000个元素,而我需要这样做大约10,000次(所以2亿次-不开玩笑)。 All in I've estimated it taking around 18 hours based on how long it takes for a fraction of the work. 总的来说,根据完成一小部分工作所需的时间,我估计大约需要18个小时。 The entire program will need to be run multiple times as well, although each new run is 100% separate an unrelated. 整个程序也需要多次运行,尽管每次新运行都是100%独立的。 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. 我已经尝试对代码进行线程化,我有一个Ryzen 1800x 8核(16线程)处理器-我已经尝试将任务拆分为15个线程(为开销和其他活动留出1个线程),并使用parallel.for循环还没有提供足够的增长。 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! 我不知道什么是AVX,但我将开始研究它,我从未编写过C ++语言,但是数学本身只是简单的方程式,我很乐意花几天/几周/几个月学习实施,如果这真的会有所作为!

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. 没有基准测试,没有办法知道 ,但是答案可能是“是”,因为C ++的性能概况与VB.NET等托管语言相比,但是JIT优化,托管到本地转换,数组访问顺序/数据局部性,而一般的编码技术都会在这里产生影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM