如何在BlackBerry中捕获HTTP吞吐量?

时间:2010-02-04 13:28:24

标签: http blackberry throughput

请帮我查一下BB编程中的HTTP吞吐量和HTTP延迟。

1 个答案:

答案 0 :(得分: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");