我在哪里可以找到一个字节来浮动查找表?
我最初正在寻找一种将字节转换为浮点数的方法,并找到了表明最快的答案是创建一个查找表。
所以我想知道是否有人知道我可以使用的现有查找表。
I initially was looking for a way convert byte to float, and found answers that indicate the fastest was is to create a lookup table.
So i was wondering if anyone know of a pre-existing lookup table that i can use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,您将使用几行代码和 for 循环或任何适合您目的的内容来初始化查找表。 仅当您对有限数量的可能输入进行大量转换时,它才有用。
下面的示例仅演示构建和使用查找表的基本技术。 除非涉及更多数学,否则如果您实现此功能,实际上会降低性能(见下文)。
代码是 C#,我没有 Objective C 的经验。在 C++ 中,数组声明会有点不同,但你明白了。
何时使用查找表?
在上面的例子中,没有性能增益,因为不涉及计算,只是从字节到浮点的转换。 考虑涉及浮点除法的情况(如您的情况):
在这种情况下,查找表应该比使用直接计算更快。 数学越复杂(三角函数等),性能增益就越大。 另一个常见用法是伽玛校正图像(指数函数)。
Normally you would initialize the lookup table using a few lines of code and a for loop or whatever suits your purpose. It's only useful if you're doing a large number of conversions on a finite number of possible inputs.
The example below is only to demonstrate the basic technique of building and using a lookup table. Unless there is more math involved, there would actually be a performance hit if you implemented this (see below).
The code is C#, I have no experience with objective C. In C++ the array declaration would be a bit different, but you get the idea.
When to use a lookup table?
In the above example, there is no performance gain, because no calculation is involved, just a conversion from byte to float. Consider the case where floating point division is involved (like your case):
In this case, the lookup table should be faster than using direct calculation. The more complex the math (trigonometry, etc.), the bigger the performance gain. Another common usage is gamma correcting an image (exponential function).
查找表? 我们不需要讨厌的查找表!
Lookup table? We don't need no stinkin' lookup tables!