math.asin函数vb.net的代码优化 [英] Code optimisation of math.asin function vb.net

查看:131
本文介绍了math.asin函数vb.net的代码优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码行:

SomeDouble= constant1/ ((a * b) * (Math.Asin((c- a) / (a * d)) + constant2))

这两个常数是不同的,并且是在循环之外计算的,其中a-d是每次更改的变量.

The two constants are different and calculated out of the loops, a - d are variables that change each time.

从表面上看,平均速度为0.002毫秒(26,508,249次击中47,633.588秒).我遇到的问题是,它将被称为数十亿次,每次运行该软件时,点击量实际上约为200亿次.因此,如果我可以将其减小到0.001ms,则差异将很大.我知道除法是一个非常缓慢的过程,我希望计算arcsin也会很慢.如果有人可以建议是否有一种更快的计算arcsin的方法,或者有其他帮助加快这一行代码的速度,那将是很好的选择.附带一提,关于vb.net的内置数学函数是否针对速度进行了优化的任何建议都很棒,我注意到math.sqrt(somevalue)比(somevalue)^ 0.5更快.

And on the face of it it's pretty fast 0.002ms on average (47,633.588s for 26,508,249 hits). The issue I'm having is it's going to be called billions of times, literally around 20 billion hits each time the software is run. So if I can cut this down to 0.001ms the difference will be substantial. I know that dividing is a very slow process and I expect calculating arcsin is also slow. If anyone can suggest if there's a faster method of calculating arcsin or any other help in speeding up this line of code that would be great. On a side note any advice on whether vb.net's built in math functions are optimised for speed would be great I've noticed that math.sqrt(somevalue) is quicker than (somevalue)^0.5.

感谢进阶!

推荐答案

我将做一些测试,以确保Math.Asin确实是公式中最慢的部分.如果相对于其他乘法和除法而言它确实很慢,那么您可以尝试为Math.Asin实现自己的查找表.换句话说,预先计算数百万个Math.Asin值,并将它们编码到您的程序中.这样可以将程序的大小与速度进行权衡,因此,如果程序的大小无关紧要,则可能会有所帮助.

I'd do some tests to make sure that the Math.Asin really is the slowest part of the formula. If it really is slow relative to the other multiplications and divisions, then you could try implementing your own lookup table for Math.Asin. In other words, calculate millions of Math.Asin values in advance, and code them into your program. This would trade the size of your program for speed, so if program size doesn't matter, it might help.

这篇关于math.asin函数vb.net的代码优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆