gpt4 book ai didi

java - 如何用Timer计算 react 时间?

转载 作者:行者123 更新时间:2023-12-02 06:39:12 25 4
gpt4 key购买 nike

我有一个面板,其中显示一个小红色圆圈,一段时间后红色圆圈被黄色圆圈取代,用户在看到黄色圆圈时必须尽快单击面板。因此, react 时间是显示黄色圆圈的时刻与用户在大面板中单击的时刻之间的时间(以毫秒为单位)。该测试重复5次。

如何使用javax.swing.Timer计算 react 时间,使用System.currentTimeMillis()作为计时器的启动以及5次测试的平均 react 时间? (需要使用这个)

最佳答案

要计算执行时间,建议使用System.nanotime()而不是System.currentTimeMillis()看这个link了解更多信息

public static long nanoTime()

Returns the current value of the most precise available system timer, in nanoseconds.

This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary time (perhaps in the future, so values may be negative). This method provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change. Differences in successive calls that span greater than approximately 292 years (263 nanoseconds) will not accurately compute elapsed time due to numerical overflow.

关于java - 如何用Timer计算 react 时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19332750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com