Android 在一个包裹里写可包裹的东西有那么快吗?
我想估算一下将一个可包裹的对象写入一个包所需的时间。我创建了自己的parcelable类(只有两个属性:int和String),并编写了一个简短的应用程序,实例化我的parcelable类的500000个对象,将它们放入ArrayList,将ArrayList写入一个包,然后从同一个包中读取ArrayList 我很惊讶地看到,写和读这张巨大的清单是即时的。(每次0毫秒) 这样一个ArrayList可以“瞬间”编写,还是我做错了Android 在一个包裹里写可包裹的东西有那么快吗?,android,performance,Android,Performance,我想估算一下将一个可包裹的对象写入一个包所需的时间。我创建了自己的parcelable类(只有两个属性:int和String),并编写了一个简短的应用程序,实例化我的parcelable类的500000个对象,将它们放入ArrayList,将ArrayList写入一个包,然后从同一个包中读取ArrayList 我很惊讶地看到,写和读这张巨大的清单是即时的。(每次0毫秒) 这样一个ArrayList可以“瞬间”编写,还是我做错了 ... private static final
...
private static final int TEST_SIZE = 500000;
...
mList = new ArrayList<MyParcelableClass>();
for(int i=0; i<TEST_SIZE; i++){
mList.add(new MyParcelableClass(i));
}
...
Bundle testBundle = new Bundle();
mStartTime = System.currentTimeMillis();
testBundle.putParcelableArrayList("test", mList);
logTime("parcelableArrayList writing");
//parcelableArrayList writing 0ms
ArrayList<MyParcelableClass> deserialization = new ArrayList<MyParcelableClass>();
mStartTime = System.currentTimeMillis();
deserialization = testBundle.getParcelableArrayList("test");
logTime("parcelableArrayList reading");
//parcelableArrayList reading 0ms
private void logTime(String msg){
long time = System.currentTimeMillis() - mStartTime;
log(msg + " " + String.valueOf(time) + " ms");
}
private void log(String msg){
Log.i(TAG, msg);
}
。。。
私人静态最终内部测试尺寸=500000;
...
mList=新的ArrayList();
对于(inti=0;ishow您的logTime方法:)确实,这可能会有所帮助!好的,没有bug…;)您是否尝试过将计数设置得更高(或在MyParcelableClass中将更多字段添加到parcable中)。我读到parcable很快,但0毫秒似乎有点太快了