Hi Luke,
Sorry, I did miss your follow-up post. When I got your email I dug out the
modified code. I'm even more sorry to say that I introduced a dumb bug which
artificially increased the speed. I accidentally put i += size, instead of i
+= buffer.length. That artificially boosted the speed hugely by outputting a
small file duh.

Anyway with my modified code (posted below) I get:

11-28 20:58:09.859: INFO/speedtest(850): speed test a: 1370
11-28 20:58:09.889: INFO/speedtest(850): speed test b: 31

which I think is in keeping with your figures (I wouldn't my mental
arithmetic). I do note however that this idiom in your code:

FileInputStream fis = openFileInput("speedtest");
fis.read(array);
fis.close();

is unreliable and only works by chance - in general there is no guarantee
that any read will fill a buffer unless otherwise noted in the
documentation.

Hope you didn't waste too much time on my mistake!

Tom.

2008/11/28 ______ <[EMAIL PROTECTED]>

>
> I ran some more extensive tests and got the following:
>
> WRITING:
> one byte at a time written to BufferedOutputStream: 155kb/sec
> whole array written to BufferedOutputStream: 450kb/sec
> one byte at a time written to FileOutputStream: 8kb/sec
> whole array written to FileOutputStream: 453kb/sec
>
> READING:
> one byte at a time read from BufferedInputStream: 221kb/sec
> whole array read from BufferedInputStream: 47850kb/sec
> one byte at a time read from FileInputStream: 9kb/sec
> whole array read from FileInputStream: 31604kb/sec
>
> (The reading results are a little artificial as I didn't attempt any
> sort of buffer flush between tests...)
>
> This shows that (in the writing case) writing single bytes to a
> BufferedOutputStream has about a 3x overhead over writing an array to
> a BufferedOutputStream or FileOutputStream, but writing whole arrays
> to either buffered or unbuffered streams still does not come close to
> the numbers you gave.  (My arrays are much larger than the default
> buffer size of 8kb, but that shouldn't make much difference if you
> were reading actual IO throughput numbers...)
>
> Anyway the overall result is still an order of magnitude slower than
> it should be, in the fastest case (using arrays).
>
> The code is as follows.  (The two slowest cases are commented-out.)  I
> get similar numbers using NIO channels.  What am I doing differently
> from you?
>
> --
>
>                        int size = 5 * 1024 * 1024;
>                        byte[] array = new byte[size];
>
>                        long startTime = System.currentTimeMillis();
>                        BufferedOutputStream bos = new
> BufferedOutputStream(openFileOutput
> ("speedtest", MODE_PRIVATE));
>                         for (int i = 0; i < size; i++)
>                                 bos.write((byte) 0);
>                        bos.close();
>                        Log.i("speedtest", "one byte at a time written to
> BufferedOutputStream: " + ((size / 1024.0) / ((System.currentTimeMillis
> () - startTime) / 1000.0)) + "kb/sec");
>
> //                      startTime = System.currentTimeMillis();
> //                      FileOutputStream fos = openFileOutput("speedtest",
> MODE_PRIVATE);
> //                      for (int i = 0; i < size; i++)
> //                              fos.write((byte) 0);
> //                      fos.close();
> //                      Log.i("speedtest", "one byte at a time written to
> FileOutputStream: " + ((size / 1024.0) / ((System.currentTimeMillis()
> - startTime) / 1000.0)) + "kb/sec");
>
>                        startTime = System.currentTimeMillis();
>                        bos = new
> BufferedOutputStream(openFileOutput("speedtest",
> MODE_PRIVATE));
>                        bos.write(array);
>                        bos.close();
>                        Log.i("speedtest", "whole array written to
> BufferedOutputStream: "
> + ((size / 1024.0) / ((System.currentTimeMillis() - startTime) /
> 1000.0)) + "kb/sec");
>
>                        startTime = System.currentTimeMillis();
>                        FileOutputStream fos = openFileOutput("speedtest",
> MODE_PRIVATE);
>                        fos.write(array);
>                        fos.close();
>                        Log.i("speedtest", "whole array written to
> FileOutputStream: " +
> ((size / 1024.0) / ((System.currentTimeMillis() - startTime) /
> 1000.0)) + "kb/sec");
>
>                        startTime = System.currentTimeMillis();
>                        BufferedInputStream bis = new
> BufferedInputStream(openFileInput
> ("speedtest"));
>                        for (int i = 0; i < size; i++)
>                                 bis.read();
>                        bis.close();
>                        Log.i("speedtest", "one byte at a time read from
> BufferedInputStream: " + ((size / 1024.0) / ((System.currentTimeMillis
> () - startTime) / 1000.0)) + "kb/sec");
>
> //                      startTime = System.currentTimeMillis();
> //                      FileInputStream fis = openFileInput("speedtest");
> //                      for (int i = 0; i < size; i++)
> //                              fis.read();
> //                      fis.close();
> //                      Log.i("speedtest", "one byte at a time read from
> FileInputStream:
> " + ((size / 1024.0) / ((System.currentTimeMillis() - startTime) /
> 1000.0)) + "kb/sec");
>
>                        startTime = System.currentTimeMillis();
>                        bis = new
> BufferedInputStream(openFileInput("speedtest"));
>                        bis.read(array);
>                        bis.close();
>                        Log.i("speedtest", "array read from
> BufferedInputStream: " +
> ((size / 1024.0) / ((System.currentTimeMillis() - startTime) /
> 1000.0)) + "kb/sec");
>
>                        startTime = System.currentTimeMillis();
>                        FileInputStream fis = openFileInput("speedtest");
>                        fis.read(array);
>                        fis.close();
>                        Log.i("speedtest", "array read from FileInputStream:
> " + ((size /
> 1024.0) / ((System.currentTimeMillis() - startTime) / 1000.0)) + "kb/
> sec");
>
>                        deleteFile("speedtest");
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to