0

因此,我正在为 android 构建几个基准应用程序,以评估不同的技术(Flex、、、NativeHtml5)并根据我的方法确定哪个是最好的。

我遇到的问题是,虽然 Native 应用程序在简单的算术测试中是无与伦比的,但在读取或写入文件时却不一样。

更具体地说,该Native应用程序从 1 到 10m 的计数时间Flex为 92 毫秒,而相同的动作需要 13 秒的平均时间。

在阅读 10000 行文本时,该Native应用程序在Flex需要 450 时花费了 800 毫秒,而在编写本机应用程序时花费了 3560 毫秒,而 flex 仅花费了 860 毫秒。

第一次测试的唯一区别是本机应用程序在flex我使用Filestream. 这会导致这种不一致吗?有什么想法可以从这里开始吗?

4

1 回答 1

0

I am using java for my native. so here is my source:

Flex:

            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 Version:

{

    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"));

}

Can the difference of using bufferwriter be the source of getting different results?

于 2013-02-27T16:57:08.663 回答