可悲的是,答案远比这些建议更普通,尽管它们确实有帮助。基本上,我搞乱了我的时间表。
,我用定时码是这样的:
Ipp32s timer;
ippGetCpuFreqMhz(&timer);
Ipp64u globalStart = ippGetCpuClocks();
globalStart = ippGetCpuClocks() *2 - globalStart; //use this method to get rid of the overhead of getting clock ticks
//do some stuff
Ipp64u globalEnd = ippGetCpuClocks();
globalEnd = ippGetCpuClocks() *2 - globalEnd;
std::cout << "total runtime: " << ((Ipp64f)globalEnd - (Ipp64f)globalStart)/((Ipp64f)timer *1000000.0f) << " seconds" << std::endl;
此代码是特定于英特尔编译器,并且被设计为给极其精确的时间测量。不幸的是,这种极端精确性意味着每次运行大约需要2.5秒的成本。删除时间码删除了时间限制。
尽管运行时似乎还有延迟 - 代码会在该时间码上报0.24秒,现在报告的时间约为0.35秒,这意味着速度成本大约为50% 。
代码变更为这样:
static extern void ImageProcessing(
IntPtr inImage, //[MarshalAs(UnmanagedType.LPArray)]ushort[] inImage,
IntPtr outImage, //[MarshalAs(UnmanagedType.LPArray)]ushort[] outImage,
int inYSize, int inXSize);
和称为等:
unsafe {
fixed (ushort* inImagePtr = theInputImage.DataArray){
fixed (ushort* outImagePtr = theResult){
ImageProcessing((IntPtr)inImagePtr,//theInputImage.DataArray,
(IntPtr)outImagePtr,//theResult,
ysize,
xsize);
}
}
}
滴可执行时间0.3秒(平均三次运行的)。我的口味仍然太慢,但10倍的速度提高肯定在我老板的可接受范围内。
来源
2009-01-19 22:55:26
mmr
我从这收集的是我需要使用不安全的代码。我很酷,我会做转换并运行测试,并让你知道我的结果。 – mmr 2009-01-19 22:07:37