Please help me to findout the HTTP throughput and HTTP latency in the BB programming.
A:
You can use System.currentTimeMillis()
to get timestamps at various points in your code, then use those values to calculate timings. For example:
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");
Marc Novakowski
2010-02-04 17:54:39