我用 C++ 编写了一个 Matrix 类,我做了一个基准测试来在树莓派上测试这段代码,当我使用 arch Linux 时,计算时间是 0.4ms,当我使用 RTOS 的 ChibiOS 时,代码的运行时间是 2.5ms。两种情况的CPU频率相同(700Mhz)。可能是一个系统中的内存操作(calloc,memcpy)较慢吗?
1 回答
Since you're using doubles, it's hard float versus soft float.
Note that you must not attempt to run hard float binaries on an OS that doesn't support hard float. If you do, it will appear to work until there's a context switch between two processes that use hard float. Since the OS won't save the floating point state on context switches, they'll step on each other's floating point contexts and results will be unpredictable.
I believe the linker will catch this, so unless you write the assembly yourself and don't use any libraries, it should be difficult to run into this problem accidentally.