2010-02-04 4 views

답변

2

System.currentTimeMillis()을 사용하면 코드의 여러 지점에서 타임 스탬프를 얻은 다음 해당 값을 사용하여 타이밍을 계산할 수 있습니다. 예 :

long start = System.currentTimeMillis(); 
HttpConnection connection = (HttpConnection) Connector.open(url); 
long opened = System.currentTimeMillis(); 
String body = new String(IOUtilities.streamToBytes(connection.openInputStream())); 
long done = System.currentTimeMillis(); 

long bytes = body.length(); 
float durationSeconds = (float)(done - opened)/1000.0f; 
float bytesPerSecond = bytes/durationSeconds; 

System.out.println("Latency: " + (opened - start) + " ms"); 
System.out.println("Bandwidth: " + bytesPerSecond + " bytes per second"); 
관련 문제