我有以下代码:
from mmap import mmap
from struct import unpack
from time import time,sleep
mmap_offset =0x44c00000
mmap_size =0x48ffffff-mmap_offset
DCAN1 =0x481D0000-mmap_offset #DCAN1 registers TIRM 2.1
DCAN1_IF1CMD =0x100+DCAN1
with open("/dev/mem", "r+b") as f:
testMap=mmap(f.fileno(),mmap_size,offset=mmap_offset)
start1=time()
unpacked1=unpack("<L",testMap[DCAN1_IF1CMD:DCAN1_IF1CMD+4])[0]
end1=time()
start2=time()
unpacked2=unpack("<L",testMap[DCAN1_IF1CMD:DCAN1_IF1CMD+4])[0]
end2=time()
print end2-start2,end1-start1
可重复(在几微秒内)给我以下输出:
3.00407409668e-05 0.0001220703125
我不确定这是从哪里来的,我真的很想了解。有什么想法吗?我的版本和 CPU 信息如下。
Linux version 3.2.34 (koen@Angstrom-F16-vm-rpm) (gcc version 4.5.4 20120305 (pre
release) (GCC) ) #1 Wed Nov 21 14:17:11 CET 2012
Processor : ARMv7 Processor rev 2 (v7l)
BogoMIPS : 718.02
Features : swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x3
CPU part : 0xc08
CPU revision : 2
Hardware : am335xevm
Revision : 0000
Serial : 0000000000000000
编辑:我已更新代码以按以下方式重新运行块 10 次:
for i in xrange(10):
start2=time()
unpacked2=unpack("<L",testMap[DCAN1_IF1CMD:DCAN1_IF1CMD+4])[0]
end2=time()
print end2-start2
结果是:
9.20295715332e-05
6.103515625e-05
3.00407409668e-05
3.09944152832e-05
3.09944152832e-05
3.00407409668e-05
3.09944152832e-05
3.09944152832e-05
2.98023223877e-05
3.09944152832e-05
它似乎在 3e-05 稳定下来……无论我运行它 10 次还是 100 次。