[英]Native Android VS Flex mobile filesystem speed
因此,我正在為Android構建一些基准測試應用程序,以便評估不同的技術( Flex
, Native
, Html5
等),並根據我的方法確定哪種技術最好。
我遇到的問題是,盡管本機應用程序在簡單的算術測試中無與倫比,但在讀取或寫入文件時卻不盡相同。
更具體地說, Native
應用程序從1到10m的計數為92毫秒,而Flex
的相同動作平均需要13秒。
在讀10000行文本的Native
應用程序在800ms了當Flex
需要450,並以書面的原生應用了3560ms時,Flex只有860ms了。
第一次測試的唯一區別是,當我在flex
使用Filestream
時,本機應用程序使用了緩沖流。 這會導致這種不一致嗎? 有什么想法從這里去嗎?
我使用Java作為本機。 所以這是我的來源:
柔性:
loadingLbl.visible=true;
var startTime:int = getTimer();
te1.text=""+startTime;
var file:File = File.desktopDirectory.resolvePath("samples/test.txt");
var pathFile:String = file.nativePath;
var stream:FileStream = new FileStream()
stream.open(file, FileMode.WRITE);
for(i=0; i<=100000; i++)
{
//list.dataProvider.addItem(""+i);
stream.writeUTFBytes("word"+i+"\n");
}
stream.close();
results.text=""+file.nativePath;
var currentTime:int = getTimer();
var timeRunning:int = (currentTime - startTime);
te0.text=""+currentTime;
timerLabel.text= "Total time: "+timeRunning+" ms";
loadingLbl.visible=false;
Android版本:
{
String temp="";
TextView time = (TextView)findViewById(R.id.timerLbl);
long start=System.nanoTime();
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File myfile = new File(sdcard,"myFile.txt");
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(myfile));
for(int i=0;i<100000;i++)
{
temp="word"+i;
writer.write(temp);
writer.newLine();
}
writer.flush();
writer.close();
} catch (FileNotFoundException e) {
// handle exception
} catch (IOException e) {
// handle exception
}
TextView tv = (TextView)findViewById(R.id.result);
//Set the text
tv.setText("Last word was: "+temp);
long end=System.nanoTime();
time.setText("Took: " + ((end - start) / 1000000+"ms"));
}
使用bufferwriter的不同之處能否成為獲得不同結果的源頭?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.