简体   繁体   中英

Native Android VS Flex mobile filesystem speed

So i am building a couple of benchmark apps for android in order to evaluate different technologies ( Flex , Native , Html5 ,etc) and determine which is best according to my method.

The problem that i came across is that while the Native app was unmatched on simple arithmetic tests it's not the same when reading or writing files.

More specific the Native application scored 92ms on counting from 1 to 10m while Flex needed an avg of 13sec for the same action.

In Reading 10000 lines of text the Native app took 800ms when Flex needed 450 and in writing the native app took 3560ms when flex took only 860ms.

The only difference on the first test was that the native app used a bufferstream when in flex i used a Filestream . Can this cause this inconsistency? Any ideas where to go from here?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM