担心我的网络应用程序的性能,我想知道哪个"if/else"或switch语句在性能方面更好?
我正在编写一个应用程序,它读取大型浮点数并使用它们执行一些简单的操作.我正在使用花车,因为我认为它比双打快,但经过一些研究后我发现这个主题有些混乱.任何人都可以详细说明这个吗?
我正在阅读"加速C++".我发现一句话说"有时double执行速度比floatC++ 快".读完句子后,我感到困惑float和double工作.请向我解释这一点.
当预先形成arithimic(+ - */%)时,哪个是更快,双倍还是浮动,并且为了内存的原因值得使用float吗?精度不是一个问题.
即使想到这一点,也要随意叫我疯了.只是好奇,因为我看到我正在使用的花车数量越来越大.
编辑1:这是在android下的唯一原因是因为这是我认为记忆很重要的地方; 我甚至不会问这个桌面开发.
我一直试图找到有关在图形硬件上使用float vs double的性能的信息.我已经在CPU上找到了关于float vs double的大量信息,但是GPU的这种信息更加稀缺.
我使用OpenGL进行编码,因此,如果您认为应该知道该API的任何特定信息,那就让我们了解一下.
我知道如果程序将大量数据移入/移出图形硬件,那么使用浮点数可能会更好,因为双倍需要两倍的带宽.我的询问更多的是图形硬件如何处理它.据我所知,现代英特尔CPU将浮点/双精度转换为80位实数进行计算(不包括SSE指令),因此这两种类型的速度同样快.现代显卡做这样的事吗?浮动和双重表现现在大致相等?是否有任何强有力的理由使用一个而不是另一个?
我正在研究摄像机拍摄的1000万像素图像.
目的是在矩阵(二维阵列)中记录每个像素的灰度值.
我第一次使用GetPixel,但它需要25秒才能完成.现在我使用Lockbits但是它需要10秒,如果我不将结果保存在文本文件中则需要3秒.
我的导师说他们不需要注册结果,但3秒仍然太慢.我在我的程序中做错了什么,或者我的应用程序有比Lockbits更快的东西吗?
这是我的代码:
public void ExtractMatrix()
{
Bitmap bmpPicture = new Bitmap(nameNumber + ".bmp");
int[,] GRAY = new int[3840, 2748]; //Matrix with "grayscales" in INTeger values
unsafe
{
//create an empty bitmap the same size as original
Bitmap bmp = new Bitmap(bmpPicture.Width, bmpPicture.Height);
//lock the original bitmap in memory
BitmapData originalData = bmpPicture.LockBits(
new Rectangle(0, 0, bmpPicture.Width, bmpPicture.Height),
ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
//lock the new bitmap in memory
BitmapData newData = bmp.LockBits(
new Rectangle(0, 0, bmpPicture.Width, bmpPicture.Height),
ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
//set …Run Code Online (Sandbox Code Playgroud) 我从http://blog.shay.co/newtons-method/中提取了此代码:
//a - the number to square root
//times - the number of iterations
public double Sqrt(double a, int times)
{
if (a < 0)
throw new Exception("Can not sqrt a negative number");
double x = 1;
while (times-- > 0)
x = x / 2 + a / (2 * x);
return x;
}
Run Code Online (Sandbox Code Playgroud)
对于数字的迭代次数(如果存在),有什么好的经验法则? (例如,"使用n/2次迭代".)
c# ×3
performance ×3
double ×2
algorithm ×1
android ×1
c++ ×1
graphics ×1
if-statement ×1
java ×1
lockbits ×1
memory ×1
opengl ×1
precision ×1
square-root ×1