我正在尝试测量“进程”的响应时间(我正在从服务器请求数据,然后呈现数据)。我想测量从我请求数据(当我按下“发送”按钮时)到数据显示在我的 txtbox 中所花费的时间。
看起来像这样:
(these two are at the very top:)
private long a
private long b
...other code...
a = System.currentTimeMillis();
btnSend.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
String fileContents;
b = System.currentTimeMillis();
try {
fileContents = control.getFileContents(txtSearch.getText());
txtView.setText(fileContents + "\n" + "\n" + "The process took "+(b-a)+"milliseconds to execute." + "\n" + "("+((b-a)/1000)+" seconds)");
} catch (RemoteException e) {
txtView.setText("File not found");
}
}
蚂蚁它的作品,但只是第一次。如果我发送另一个请求,则时间只会添加到旧时间。第一个请求需要 2 秒,第二个请求需要 7 秒(实际上它需要 2 秒)。
我尝试通过重置 a 和 b 来规避问题,方法是:
a = 0;
b = 0;
在重置按钮中,但这似乎只会让事情变得有点疯狂。
关于如何解决问题的任何想法?
谢谢