- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试计算运行单个 ASM 指令所需的 CPU 周期数。为此,我创建了这个函数:
measure_register_op:
# Calculate time of required for movl operation
# function setup
pushl %ebp
movl %esp, %ebp
pushl %ebx
pushl %edi
xor %edi, %edi
# first time measurement
xorl %eax, %eax
cpuid # sync of threads
rdtsc # result in edx:eax
# we are measuring instuction below
movl %eax, %edi
# second time measurement
cpuid # sync of threads
rdtsc # result in edx:eax
# time difference
sub %eax, %edi
# move to EAX. Value of EAX is what function returns
movl %edi, %eax
# End of function
popl %edi
popl %ebx
mov %ebp, %esp
popl %ebp
ret
我在 *.c 文件中使用它:
extern unsigned int measure_register_op();
int main(void)
{
for (int a = 0; a < 10; a++)
{
printf("Instruction took %u cycles \n", measure_register_op());
}
return 0;
}
问题是:我看到的值太大了。我现在收到 3684414156
。这里会出什么问题?
编辑:从 EBX 更改为 EDI,但结果仍然相似。它必须与 rdtsc 本身有关。在调试器中,我可以看到第二个测量结果为 0x7f61e078,第一个为 0x42999940,减法后仍然给出 1019758392
编辑:这是我的生成文件。也许我编译不正确:
compile: measurement.s measurement.c
gcc -g measurement.s measurement.c -o ./build/measurement -m32
编辑:这是我看到的确切结果:
Instruction took 4294966680 cycles
Instruction took 4294966696 cycles
Instruction took 4294966688 cycles
Instruction took 4294966672 cycles
Instruction took 4294966680 cycles
Instruction took 4294966688 cycles
Instruction took 4294966688 cycles
Instruction took 4294966696 cycles
Instruction took 4294966688 cycles
Instruction took 4294966680 cycles
最佳答案
cpuid
破坏了 ebx
和许多其他寄存器。您需要避免在此处使用 cpuid
或将值保存在不会被破坏的地方。
关于c - 使用 RDTSC 测量时差 - 结果太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56200229/
我正在尝试创建一个程序,该程序采用两个军事时间的差异并获取其时差。 示例: **上午到下午** 时间 1:0900 时间 2:1730 时差:8 小时 30 分钟 **下午到上午** 时间 1:120
我正在尝试计算两个时间字段之间的时间差异。由于这些字段只是没有日期的时间,因此我无法使用 timestampdiff,因此我使用 timediff() 或 subtime() 。唯一的问题是,当第二次
我试图简单地计算 5:30:00 - 2:30:00 的时差。显然这应该导致 3:00:00 但是当我在控制台中执行以下代码时 var a = new Date(0,0,0,5,30,0) var b
我试图在 C 中区分两个日期,但我收到这样的输出: future date: 18-11-2013 22:8 current date: 18-11-2013 22:8 这是我的代码: #includ
我正在尝试计算截至上午 00:00 的剩余分钟数。 DELIMITER // CREATE PROCEDURE midnightCountdown() BEGIN SELECT TIME_FORMAT
我正在尝试使用 postgresql 从表(login_history as t1)中检索以分钟为单位的时差。 当我尝试这段代码时 ((date_part('hour', timestamp '201
欢迎!我有问题想问你。我正在 Laravel 5.2 中为自己编写飞行日志。在公式中,我将有起飞时间和到达时间,但我不知道如何在 laravel 中计算时间差并将其自动传递到数据库。因此,最简单的方法
我已经查看了有关此主题的其他问答,但没有找到任何帮助。 我的应用记录比赛结果并保存到文件。 第一次点击它会写入当前时间,当运行者完成后,它会再次记录当前时间。 如何计算这两个时间以获得比赛时间? 这是
我有非常简单的代码来计算两次之间的差异: import java.text.SimpleDateFormat; import java.util.Date; import java.util.Greg
在 Python 中比较 2 次以加快测试一段代码的正确方法是什么?我尝试阅读 API 文档。我不确定我是否理解 timedelta。 到目前为止,我有这个代码: from datetime impo
这个问题非常类似于Best timestamp format for CSV/Excel? : 我正在写一个 CSV 文件。我需要编写至少精确到秒,最好精确到毫秒的时间跨度(又名时差)。 CSV 文件
我试图通过输入时间格式计算12小时内的java时差,当我输入开始时间11:58:10 pm和结束时间12:02时效果很好:15 点。但当我输入 12:00:00 am 和 12:00:00 pm 时,
因此,对于一项作业,我们必须编写一个程序,该程序需要两次军事时间,并显示它们之间的小时和分钟差异,假设第一次是两次时间中较早的一次。我们不允许使用 if 语句,因为它在技术上尚未被学习。这是运行时的示
我必须为分布在全局各地的所有人员制定 24 小时时间表。 例如,某人可以在 10:00 开始工作,并在 19:00 结束工作,因此获得时差非常简单,因为结束时间和开始时间在同一天。但是,如果我有人在
使用 ntp 时间时,(英国)返回的时间总是比实际时间少一小时。例如:现在时间是 13.35 但当我说日期时,它返回 12.35。有什么建议? try: c = ntplib.
我有一个应用程序,它在登录时记录时间,在退出时记录退出时间。 我的表有 IN_TIME 和 OUT_TIME 这些列中的数据示例: IN_TIME = 16:06:46 结束时间 = 16:08:07
我使用 $_POST 将变量从 ajax 表单发布到 php 服务器端我有两个变量,时间和金额。在服务器中,我有一个 MYSQL 数据库,其中包含 _end_time (数据类型:时间)和金额(数据类
我正在尝试计算在这里工作的人的轮类模式,从结束时间减去开始时间在大多数情况下都有效,但如果他们通宵工作则不行。例如,从 10pm 到 6am 工作的人将显示为: 22:00 - 06:00 我希望返回
任何人都可以提供一个 Excel 方程来计算两个 UTC 时间戳之间的差异。 UTC 时间戳的格式为 yyyymmddhhmmssZ(例如 20160127175049Z)。时间戳之间的差异最多为几个
我在大学学习一门名为“智能机器”的类(class)。我们向我们介绍了 3 种强化学习方法,并通过这些方法我们获得了何时使用它们的直觉,我引用: Q-Learning - 当 MDP 无法解决时最好。
我是一名优秀的程序员,十分优秀!