Android 3.2 上 HttpPost 的 HttpClient 执行速度明显慢于 2.3.3
有人知道为什么下面的代码在 Android 3.2 (Samsung Galaxy 10.1" Tab) 上的运行速度比在 2.3.3 (Motorola Droid X) 上慢 4 倍吗?
在 Android 2.3.3 上,client.execute() 调用平均需要 350ms。 在 3.2 下,平均需要 1400ms
此外,结果是相同的。它是在 UI 线程还是后台线程中运行。
这是操作系统错误还是硬件问题?或者我在代码中没有做正确的事情?不幸的是,我无法将 ADB 连接到我的 3.2 虚拟设备。我不能排除硬件问题,但我的直觉告诉我这是一个 Honeycomb 问题。
HttpResponse resp = null;
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpClient client = new DefaultHttpClient(params);
ArrayList<BasicNameValuePair> postParms = new ArrayList<BasicNameValuePair>();
postParms.add(new BasicNameValuePair("name", "test"))
try
{
HttpPost hp = new HttpPost("http://myserver/path/method");
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParms);
hp.setEntity(formEntity);
Long start = SystemClock.elapsedRealtime();
resp = client.execute(hp);
Long stop = SystemClock.elapsedRealtime();
Log.i("Time = " + (stop-start) + "ms");
}
...
Anyone know why the code below would run about 4 times slower on Android 3.2 (Samsung Galaxy 10.1" Tab) than it does on 2.3.3 (Motorola Droid X)?
On Android 2.3.3, the client.execute() call takes on average 350ms. Under 3.2 it takes on average 1400ms.
Also, the results are the same regardless of whether it is run in the UI thread or a background thread.
Is this an OS bug or hardware issue? Or am I not doing something right in my code? Unfortunately I can't get ADB to attach to my 3.2 virtual device, so I can't rule out hardware problems, but my gut feeling tells me this is a Honeycomb issue.
HttpResponse resp = null;
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpClient client = new DefaultHttpClient(params);
ArrayList<BasicNameValuePair> postParms = new ArrayList<BasicNameValuePair>();
postParms.add(new BasicNameValuePair("name", "test"))
try
{
HttpPost hp = new HttpPost("http://myserver/path/method");
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParms);
hp.setEntity(formEntity);
Long start = SystemClock.elapsedRealtime();
resp = client.execute(hp);
Long stop = SystemClock.elapsedRealtime();
Log.i("Time = " + (stop-start) + "ms");
}
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您没有进行其他计时,请安装终端并查看 Galaxy Tab 上的
top
,以确保 CPU 没有被 android.process.media 等消耗。If you're not timing anything else, install a terminal and look at
top
on the Galaxy Tab, to be sure that CPU isn't being consumed by e.g. android.process.media.